-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Next.js includes useSyncExternalStore shim even with React 18 #37197
Comments
At the time Since |
My understanding is that |
Another related aspect is the documentation. The documentation puts the Suspense version at the end and also says something about "SSR in concurrent mode" not being ready. Which I think is outdated wording (there is no "mode", and SSR works fine with it). So I think the docs need to change to emphasize the approach best for React 18 (whichever it is). |
I just checked the source code of Next.js and the PR that introduces the Maybe in the future, Next.js would add this as a feature.
The documentation does look kinda outdated and does not explicitly mention which one is preferred ( I can't speak for the Next.js team, but I guess adding cc @huozhi Correct me if I am wrong. |
Another thought: When to use
When to use
|
Hmm. I was under the impression that there’s some Babel or webpack plugin that inserts preload hints regardless of the options argument. Maybe that’s wrong. |
The issue seems to be that it's hard to tree-shake the shim out of the bundle when the condition is relying on the runtime. We need some extra hint (like process env var for react 18 in next.js) for bundler to erase it properly var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim; |
Just a question: Is there any benefit to using
IMHO the issue is little more than that. When And even more than that. In the end, if a website only uses (But if you use |
Previously we're trying to add a support for We can recommend the |
When using `next/dynamic` with `suspense: true`, the API will opt into `React.lazy` with react 18. But previously it doesn't preload the dynamic chunks. This pr will include the chunks into initial html for faster hydration instead of loading the chunk until the script is executed. This makes `next/dynamic` has a significant difference from `React.lazy` api x-ref: #37197 (comment) x-ref: #37244
We add chunk preloading support for |
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. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
This brings in an external package:
next.js/packages/next/shared/lib/loadable.js
Line 25 in 26459ef
However, React 18 already supports
useSyncExternalStore
directly.Expected Behavior
Don't bundle the shim when the user is on React 18+.
To Reproduce
Create a new Next.js project.
The text was updated successfully, but these errors were encountered: