-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Allow server-only in server targets and client-only in client components targets to be available #55394
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Secrets | View in Orca |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Secrets | View in Orca |
Tests Passed |
373984e to
7737a0d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the code refactoring!
| optimize_barrel_exports: None, | ||
| optimize_server_react: None, | ||
| disable_checks: false, | ||
| bundle_target: String::from("default").into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an enum, shouldn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, enum will be better, add a reminder for myself to refactor it later. thanks for suggestion 👍
|
@huozhi @timneutkens Just a big thank you from myself... This unblocks us for Next and so we can proceed. In general, how long does it take for canary to be cut into a new version. However, thank you very much everyone. This has been tested and it works. |
|
@barryengineerapart glad to hear it's confirmed working! thanks |
We need to disable the default treat `middleware` and `pages/api` as server-only, unless users explictly import "server-only" to poison it. This will avoid the case that when a library is mixing "client-only" API and shared components API in one bundle, and the shared API is used in middleware or `pages/api` that might cause error. See the test case added. Follow up for #55394
Users want to use
server-onlyto restrict the middleware / app routes / pages api, but now it's failing as we're treating them as different webpack layers, but validating theserver-onlyonly with server components layers.Here we modify the rules a bit to let everyone can use "server-only" for the bundles that targeting server-side.
For next-swc transformer, we introduce the new option
bundleTypewhich only has"server" | "client" | "default"3 values:serverfor server-side targets, like server components, app routes, pages api, middlewareclientfor client components targets such as client components app pages, or page routes under pages directory.defaultfor environment like jest, we don't validate module graph with swc, replaced thedisable_checksintroduced #54891.Refactor a bit webpack-config to adapt to the new rules, after that
server-onlywill be able to used in the server-side targets conventions like middleware andpages/apiFixes #43700
Fixes #54549
Fixes #52833
Closes NEXT-1616
Closes NEXT-1607
Closes NEXT-1385