(ssr) - create initial template for ssr plugin#400
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.
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
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.
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
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