-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
Error in Dynamic Import example #487
Comments
This doesn't seem related to vps, see https://brillout.github.io/rules/. Feel free to object. |
I don't understand your statement. At a bare minimum, it's related to the VPS docs, as the provided example doesn't work properly. From a broader point of view, this appears to be the only way of achieving client-only components while also using SSR/SSG (not the SPA page.client.* formatting) - if VPS can't be used this way, does that mean that VPS is invalid for all such use cases? Edit: I've further simplified the example to verify that React.Suspense is not the root of the problem. |
It's a user land thing: you're supposed to use React.lazy. |
No, I only removed that to simplify the example. I've created a fork with an example of the problem: main...arthurgailes:vite-plugin-ssr:ssr-client-fix The main code:
|
I'm actually rewriting the docs as we speak. |
Alright, here it is: https://vite-plugin-ssr.com/dynamic-import. Apologies for the subpar docs about this. Hope it's better now. Get rid of branches like |
Thanks very much. Unfortunately, this opens a new can of worms. I've updated the fork here: main...arthurgailes:vite-plugin-ssr:ssr-client-fix The new error message: "Uncaught Error: The server did not finish this Suspense boundary: The server used "renderToString" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to "renderToPipeableStream" which supports Suspense on the server" Then, if I switch to renderToPipeableStream, I get a new error on the server: "[Wrong Usage][dangerouslySkipEscape(str)] Argument I'm not familiar enough with the components of in _default.page.server.jsx to pursue this further, sorry. |
(Still) a user land thing. As for the last error double check the streaming docs. |
Let me know if you believe there is a problem that is caused by vite-plugin-ssr (so far I'm fairly confident that it's not the case). |
Thank you again for your help. I've attempted to add an example to the project of how to implement this in practice. |
Neat 💯. |
I've come to realize my example is actually a poor one. As far as I can tell, there simply is no idiomatic way to load a client-only component within SSR/SSG for vite-plugin-ssr, a la the Next.js dynamic import feature. My leaflet branch shows this problem with react-leaflet:
Rendering this way doesn't make the component client-side only; it makes the component render lazily on the client side and the server side. So it can't help with code that can only be run on the client (leaflet, mapbox, Tableau, etc). The only option here seems to be to use the "isBrowser" path above and live with the hydration errors, or render the whole page in SPA. This seems low on the priority list, but maybe make a note of it in the docs? |
Yes the docs should be updated. Thanks for the udpate. Isn't there a way to tell React to render the Suspense fallback on the server-side? There must be a way since AFAICT it's what Next.js's |
It seems like they feed suspense a conditional component, don't follow well enough to implement, but the gist is:
Their NoSSR function throws an error on the server, but they must have some back-end mechanism for collecting it that I'm not seeing. |
I'm thinking a simpler solution could be to use a wrapper that renders |
Oy, I feel like an idiot. That works!
|
I've updated my example page to use this example. Thanks for your help. |
FYI you don't need Thanks for the example, I'll update the VPS docs. |
Correct on useEffect; updated example. React Suspense is required to process React.lazy, as the import is async. |
Docs updated https://vite-plugin-ssr.com/dynamic-import. Thanks for reaching out and apologies for the initial push back. |
Description
When using the example on dynamic loading with a React.Suspense component, I receive the following error:
Uncaught Error: Hydration failed because the initial UI does not match what was rendered on the server.
The page still works, but I'm assuming I'm losing some SSR benefit here. I believe this is resulting from the components in node and the browser being different - even when they call the same underlying function. As an example, the code below produces the same error, adapted from the example:
Error Stack
The text was updated successfully, but these errors were encountered: