-
-
Notifications
You must be signed in to change notification settings - Fork 107
(ssr) - create initial template for ssr plugin #400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Size Change: +10 B (0%) Total Size: 690 kB
ℹ️ View Unchanged
|
if (typeof window !== 'undefined') { | ||
if (document.querySelector('.app')) { | ||
hydrate(<App />, document.body); | ||
} else { | ||
render(<App />, document.body); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary, given that hydrate
is a wrapper that calls render
if ! document.querySelector('script[type=isodata]')
? (I suppose the answer is yes if script[type=isodata]
isn't generated by the SSR method implemented in this PR, but in this case could this be clarified in a code comment, for the avoidance of doubt?)
Code reference:
wmr/packages/preact-iso/hydrate.js
Lines 8 to 15 in fe51b7e
let isodata = document.querySelector('script[type=isodata]'); | |
// @ts-ignore-next | |
parent = parent || (isodata && isodata.parentNode) || document.body; | |
if (!initialized && isodata) { | |
hydrativeRender(jsx, parent); | |
} else { | |
render(jsx, parent); | |
} |
The current documentation states:
https://github.com/preactjs/wmr/blob/main/packages/preact-iso/README.md#hydratejs
hydrate() is a thin wrapper around Preact's hydrate() method. It performs hydration when the HTML for the current page includes pre-rendered output from prerender(). It falls back to plain rendering in any other cases, which is useful if you're not pre-rendering during development. This method also checks to make sure its running in a browser context before attempting any rendering - if not, it does nothing.
if (typeof window !== 'undefined') { | ||
hydrate(<App />, document.body); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will probably see this in PR #403 ( #403 (review) ) but just in case this goes under the radar for this PR #400, here it is again:
The typeof window !== 'undefined'
browser check can be removed.
References:
wmr/packages/preact-iso/hydrate.js
Line 7 in fe51b7e
if (typeof window === 'undefined') return; |
https://github.com/preactjs/wmr/blob/main/packages/preact-iso/README.md#hydratejs
This method also checks to make sure its running in a browser context before attempting any rendering - if not, it does nothing.
Currently facing a few Windows issues but slowly getting there, this is a WIP
This is the code from #169