You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First off, thanks for publishing this repo. It's straight forward and better written than Meta's.
I wanted to post this in case it helps anyone and also get feedback. I am trying to build a pure React SSR setup like yourself but using a bundler (Rollup) for more optimized code splitting on the client (goodbye Next.JS 👋) . I ran into 3 problems with hacks to resolve but wish I didn't have to, so curious if I'm missing something.
When I use the HTML component when the client bundle loads, I get UI hydration mismatch errors from the server. To resolve, I check to see if I'm client and if I am, I only hydrate <App /> and not the surrounding HTML.
Conditional hydration example:
importAppRoutesfrom"./AppRoutes";importHtmlfrom"./components/Html";exportdefaultfunctionApp(){if(typeofwindow!=="undefined"){return<AppRoutes/>;}return(<Htmltitle="React SSR Demo"><AppRoutes/></Html>);}
I got non-deterministic behavior with onShellReady when streaming my components that use dynamic imports. On initial page load the DOM would be just a white page and the rendered HTML would say JavaScript not enabled. To resolve I used onAllReady. This is fine for SEO optimized applications for full SSG, but it's not ideal for SSR applications trying to optimize hydration time.
I actually have always found the bootstrapScripts on the renderToPipeableStream API to be awkward. It seems, at least to me, it kind of randomly injects the hydration script randomly into the DOM. Unfortunately, when using it here I could only get it to show up after the root html tag which isn't valid.
I removed that line completely and just modified the Html component like so:
import{PropsWithChildren}from"react";typeHtmlProps=PropsWithChildren<{title: string}>;exportdefaultfunctionHtml({ children, title }: HtmlProps){return(<htmllang="en"><head><metacharSet="utf-8"/><metaname="viewport"content="width=device-width, initial-scale=1"/><metaname="theme-color"content="#000000"/><metaname="description"content="Web site created using create-react-app"/><title>{title}</title></head><body><noscriptdangerouslySetInnerHTML={{__html: `<b>Enable JavaScript to run this app.</b>`,}}/><divid="root">{children}</div><scriptdeferasynctype="module"src="/index.js"></script></body></html>);}
I'll try and post a repo soon for complete repro, but open to any feedback or code!
The text was updated successfully, but these errors were encountered:
First off, thanks for publishing this repo. It's straight forward and better written than Meta's.
I wanted to post this in case it helps anyone and also get feedback. I am trying to build a pure React SSR setup like yourself but using a bundler (Rollup) for more optimized code splitting on the client (goodbye Next.JS 👋) . I ran into 3 problems with hacks to resolve but wish I didn't have to, so curious if I'm missing something.
<App />
and not the surrounding HTML.Conditional hydration example:
onShellReady
when streaming my components that use dynamic imports. On initial page load the DOM would be just a white page and the rendered HTML would say JavaScript not enabled. To resolve I usedonAllReady
. This is fine for SEO optimized applications for full SSG, but it's not ideal for SSR applications trying to optimize hydration time.Example SSR handling with Express
bootstrapScripts
on therenderToPipeableStream
API to be awkward. It seems, at least to me, it kind of randomly injects the hydration script randomly into the DOM. Unfortunately, when using it here I could only get it to show up after the roothtml
tag which isn't valid.I removed that line completely and just modified the
Html
component like so:I'll try and post a repo soon for complete repro, but open to any feedback or code!
The text was updated successfully, but these errors were encountered: