The Wayback Machine - https://web.archive.org/web/20201129011351/https://github.com/facebook/react/pull/20304
Skip to content
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

Add flight specific entry point for react package #20304

Merged
merged 1 commit into from Nov 20, 2020

Conversation

@sebmarkbage
Copy link
Member

@sebmarkbage sebmarkbage commented Nov 20, 2020

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.

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.
@codesandbox
Copy link

@codesandbox codesandbox bot commented Nov 20, 2020

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:

Sandbox Source
React Configuration
"./build-info.json": "./build-info.json",
"./jsx-runtime": "./jsx-runtime.js",
"./jsx-dev-runtime": "./jsx-dev-runtime.js",
"./": "./"

This comment has been minimized.

@sebmarkbage

sebmarkbage Nov 20, 2020
Author Member

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.

@sizebot
Copy link

@sizebot sizebot commented Nov 20, 2020

Details of bundled changes.

Comparing: 89d4fe1...5413001

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-jsx-runtime.profiling.min.js 0.0% +0.2% 970 B 970 B 607 B 608 B NODE_PROFILING
React-profiling.js 0.0% 0.0% 16.37 KB 16.37 KB 4.27 KB 4.27 KB FB_WWW_PROFILING
React-dev.js 0.0% 0.0% 87.45 KB 87.45 KB 20.98 KB 20.98 KB RN_FB_DEV
React-prod.js 0.0% 🔺+0.1% 16.63 KB 16.63 KB 4.43 KB 4.43 KB RN_FB_PROD
React-profiling.js 0.0% +0.1% 16.63 KB 16.63 KB 4.43 KB 4.43 KB RN_FB_PROFILING
react-jsx-dev-runtime.profiling.min.js 0.0% +0.3% 464 B 464 B 321 B 322 B NODE_PROFILING
react-unstable-index.server.development.js n/a n/a 0 B 463 B 0 B 336 B NODE_DEV
react-unstable-index.server.production.min.js n/a n/a 0 B 373 B 0 B 278 B NODE_PROD
React-dev.js 0.0% 0.0% 95.58 KB 95.58 KB 23.3 KB 23.3 KB FB_WWW_DEV
React-prod.js 0.0% 0.0% 16.37 KB 16.37 KB 4.27 KB 4.27 KB FB_WWW_PROD

Size changes (stable)

Generated by 🚫 dangerJS against 5413001

"unstable-cache.js"
],
"main": "index.js",
"exports": {
".": {
"react-server": "./unstable-index.server.js",

This comment has been minimized.

@acdlite

acdlite Nov 20, 2020
Member

Didn't know this feature existed, that's cool

This comment has been minimized.

@bvaughn

bvaughn Nov 20, 2020
Contributor

Was thinking the same thing. Just finished reading about it myself.

@sebmarkbage
Copy link
Member Author

@sebmarkbage sebmarkbage commented Nov 20, 2020

Note that this would have implications if we publish a minor from this branch.

@sizebot
Copy link

@sizebot sizebot commented Nov 20, 2020

Details of bundled changes.

Comparing: 89d4fe1...5413001

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-unstable-cache.development.js 0.0% +0.2% 1.05 KB 1.05 KB 588 B 589 B NODE_DEV
react-unstable-cache.production.min.js 0.0% 🔺+0.2% 867 B 867 B 563 B 564 B NODE_PROD
react-unstable-cache.profiling.min.js 0.0% +0.2% 866 B 866 B 562 B 563 B NODE_PROFILING
react-jsx-dev-runtime.profiling.min.js 0.0% +0.3% 477 B 477 B 330 B 331 B NODE_PROFILING
react.development.js 0.0% 0.0% 108.3 KB 108.3 KB 26.5 KB 26.5 KB UMD_DEV
react-unstable-index.server.development.js n/a n/a 0 B 65.42 KB 0 B 17.81 KB NODE_DEV
react.production.min.js 0.0% -0.0% 11.58 KB 11.58 KB 4.58 KB 4.58 KB UMD_PROD
react-unstable-index.server.production.min.js n/a n/a 0 B 6.17 KB 0 B 2.56 KB NODE_PROD
React-dev.js 0.0% 0.0% 94.59 KB 94.59 KB 23.07 KB 23.07 KB FB_WWW_DEV

React: size: 0.0%, gzip: -0.0%

Size changes (experimental)

Generated by 🚫 dangerJS against 5413001

@acdlite
Copy link
Member

@acdlite acdlite commented Nov 20, 2020

Oh yeah. Prefix it?

@acdlite
Copy link
Member

@acdlite acdlite commented Nov 20, 2020

Throwing in the stable channel seems fine, though

@sebmarkbage
Copy link
Member Author

@sebmarkbage sebmarkbage commented Nov 20, 2020

It’s prefixed but the package json changes can’t be prefixed in case the resolution causes breakages.

@sebmarkbage sebmarkbage merged commit d93b58a into facebook:master Nov 20, 2020
34 checks passed
34 checks passed
Facebook CLA Check Contributor License Agreement is valid!
Details
ci/circleci: RELEASE_CHANNEL_stable_yarn_build Your tests passed on CircleCI!
Details
ci/circleci: RELEASE_CHANNEL_stable_yarn_lint_build Your tests passed on CircleCI!
Details
ci/circleci: RELEASE_CHANNEL_stable_yarn_test_dom_fixtures Your tests passed on CircleCI!
Details
ci/circleci: build_devtools_and_process_artifacts Your tests passed on CircleCI!
Details
ci/circleci: build_devtools_scheduling_profiler Your tests passed on CircleCI!
Details
ci/circleci: process_artifacts Your tests passed on CircleCI!
Details
ci/circleci: process_artifacts_experimental Your tests passed on CircleCI!
Details
ci/circleci: setup Your tests passed on CircleCI!
Details
ci/circleci: sizebot_experimental Your tests passed on CircleCI!
Details
ci/circleci: sizebot_stable Your tests passed on CircleCI!
Details
ci/circleci: yarn_build Your tests passed on CircleCI!
Details
ci/circleci: yarn_flow Your tests passed on CircleCI!
Details
ci/circleci: yarn_lint Your tests passed on CircleCI!
Details
ci/circleci: yarn_lint_build Your tests passed on CircleCI!
Details
ci/circleci: yarn_test Your tests passed on CircleCI!
Details
ci/circleci: yarn_test-classic Your tests passed on CircleCI!
Details
ci/circleci: yarn_test-classic_prod Your tests passed on CircleCI!
Details
ci/circleci: yarn_test-classic_prod_variant Your tests passed on CircleCI!
Details
ci/circleci: yarn_test-classic_variant Your tests passed on CircleCI!
Details
ci/circleci: yarn_test-stable Your tests passed on CircleCI!
Details
ci/circleci: yarn_test-stable_build Your tests passed on CircleCI!
Details
ci/circleci: yarn_test-stable_build_prod Your tests passed on CircleCI!
Details
ci/circleci: yarn_test-stable_persistent Your tests passed on CircleCI!
Details
ci/circleci: yarn_test-stable_prod Your tests passed on CircleCI!
Details
ci/circleci: yarn_test-www Your tests passed on CircleCI!
Details
ci/circleci: yarn_test-www_prod Your tests passed on CircleCI!
Details
ci/circleci: yarn_test-www_prod_variant Your tests passed on CircleCI!
Details
ci/circleci: yarn_test-www_variant Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_build Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_build_devtools Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_build_prod Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_prod Your tests passed on CircleCI!
Details
ci/codesandbox Building packages succeeded.
Details
@sebmarkbage
Copy link
Member Author

@sebmarkbage sebmarkbage commented Nov 20, 2020

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".

@sebmarkbage
Copy link
Member Author

@sebmarkbage sebmarkbage commented Nov 20, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.