-
Notifications
You must be signed in to change notification settings - Fork 27k
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
React.lazy() content HTML does not get included in SSG output #33879
Comments
QQ: Is setting |
No. (But SSR appears to work without it, and it does include "hello, world" in SSR output with |
Without |
Ahhhh that's why it worked at all. I see. |
Yeah, this is one of several reasons that I think we'd really be in favor of an option to preserve React 17 Suspense SSR semantics unless explicitly opted in |
I see. So basically there's no way to try this now (though we always do SSG) because opting into the flag enables the runtime, etc. But then when that issue is fixed, we can try again. |
You mean in renderToString? If the way you opt into the new "streaming" mode, even if buffered, is by upgrading to React 18, then you'd get both upgrades so there's no way to get into this intermediate state. You can still get the problem with data being different but lots of legit use cases don't have those (React.lazy being one) issues. So I think you really need to discover it by seeing the bug in your library. |
The way the client upgrade path works is that the existing API keeps working but warns you to rename to createRoot. So it's deprecated but you have an upgrade path. We could do the same for renderToString but it would be the same API signature so if you do need to keep it, it would be unnecessary. However, doing the exercise would force you to make a choice and hopefully use the streaming one. The end result would be that Next.js should only have the streaming one on though. |
That makes sense. Let me see why this isn't already the case. |
Yeah, I think we can change this (I opened #33886). We should probably also make |
As per React 18 recommendation, we should use e.g. `renderToReadableStream` whenever we use `createRoot`. This is particularly important for currently supported suspense features like `React.lazy` to work properly during SSR. However, unless you have opted in to streaming support (via [the `runtime` flag](#34068)), we will wait until `onCompleteAll` before sending it (via the `generateStaticHTML` flag). --- Fixes #33879
As per React 18 recommendation, we should use e.g. `renderToReadableStream` whenever we use `createRoot`. This is particularly important for currently supported suspense features like `React.lazy` to work properly during SSR. However, unless you have opted in to streaming support (via [the `runtime` flag](vercel#34068)), we will wait until `onCompleteAll` before sending it (via the `generateStaticHTML` flag). --- Fixes vercel#33879
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Run
next info
(available from version 12.0.8 and up)What version of Next.js are you using?
12.0.10
What version of Node.js are you using?
16.13.0
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
next start
Describe the Bug
@devknoll asked me to file an issue for this. Basically, I'm observing that with React experimental versions, SSG doesn't wait for
lazy()
to be resolved and outputs the Suspense fallback HTML. Whereas I would've expected it to include content in SSG.I'm not sure if this means
import()
needs to be compiled differently, or something.A similar issue is that in SSR mode, the first hit will get fallback HTML and the next hits will get content HTML. Because the module is cached now.
Expected Behavior
HTML output of SSG includes the SSR content of the lazy child.
To Reproduce
Create a new clean project.
Add experimental React versions to it.
Page code:
Component code:
Run
yarn build
and thenyarn start
.Observe that the served HTML does not include
hello, world!
but does includeLoading...
.The text was updated successfully, but these errors were encountered: