-
Notifications
You must be signed in to change notification settings - Fork 50.5k
Add flight specific entry point for react package #20304
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
This configures the Flight fixture to use the "react-server" environment. This allows the package.json exports field to specify a different resolution in this environment. I use this in the "react" package to resolve to a new bundle that excludes the Hooks that aren't relevant in this environment like useState and useEffect. This allows us to error early if these names are imported. If we actually published ESM, it would we a static error. Now it's a runtime error. You can test this by importing useState in Container.js which is used by the client and server.
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 5413001:
|
| "./build-info.json": "./build-info.json", | ||
| "./jsx-runtime": "./jsx-runtime.js", | ||
| "./jsx-dev-runtime": "./jsx-dev-runtime.js", | ||
| "./": "./" |
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.
The exports protocol is an allow list so we must list everything we want to expose here. That's actually great because we can explicitly forbid deep linking. Unfortunately our build tooling is using this same file to find things so we need to export everything until we fix that.
Details of bundled changes.Comparing: 89d4fe1...5413001 react
Size changes (stable) |
| "main": "index.js", | ||
| "exports": { | ||
| ".": { | ||
| "react-server": "./unstable-index.server.js", |
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.
Didn't know this feature existed, that's cool
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.
Was thinking the same thing. Just finished reading about it myself.
|
Note that this would have implications if we publish a minor from this branch. |
Details of bundled changes.Comparing: 89d4fe1...5413001 react
React: size: 0.0%, gzip: -0.0% Size changes (experimental) |
|
Oh yeah. Prefix it? |
|
Throwing in the stable channel seems fine, though |
|
It’s prefixed but the package json changes can’t be prefixed in case the resolution causes breakages. |
|
The "react-server" name is confusing because it doesn't apply to SSR, but we decided to settle on that. SSR is not "server environment". It's an "emulated client environment". |
|
Unfortunately it doesn't make sense to add a "react-client" resolution. That's just the default. Even if we did in some new tooling, React in general isn't that opinionated about configuring this stuff so not all environments would resolve it. |
| lazy, | ||
| memo, | ||
| useCallback, | ||
| useContext, |
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.
is createContext not available in server components?
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.
No. There will likely be a new type of context like a "server context" that's serializable or something like that.
|
Hi, Could the changes in this PR, specifically adding the |
This configures the Flight fixture to use the "react-server" environment.
This allows the package.json exports field to specify a different resolution in this environment.
I use this in the "react" package to resolve to a new bundle that excludes the Hooks that aren't relevant in this environment like useState and useEffect.
This allows us to error early if these names are imported. If we actually published ESM, it would we a static error. Now it's a runtime error.
You can test this by importing useState in Container.js which is used by the client and server.
We might need to also specify imports because jsx-runtime imports our own entry point.