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

Standardize condition order so that edge-lite preferred over browser #29877

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

gnoff
Copy link
Collaborator

@gnoff gnoff commented Jun 12, 2024

The export maps for react packages have to choose an order of preference. Many runtimes use multiple conditions, for instance when building for edge webpack also uses the browser condition which makes sense given most edge runtimes have a web-standards based set of APIs. However React is building the browser builds primarily for actual browsers and sometimes have builds intended for servers that might be browser compat. This change updates the order of conditions to preference specific named runtimes > node > generic edge runtimes > browser > default

The export maps for react packages have to choose an order of preference. Many runtimes use multiple conditions, for instance when building for edge webpack also uses the browser condition which makes sense given most edge runtimes have a web-standards based set of APIs. However React is building the browser builds primarily for actual browsers and sometimes have builds intended for servers that might be browser compat. This change updates the order of conditions to preference specific named runtimes > node > generic edge runtimes > browser > default
Copy link

vercel bot commented Jun 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2024 6:27pm

Comment on lines 66 to +68
"node": "./server.node.js",
"edge-light": "./server.edge.js",
"browser": "./server.browser.js",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to add one concern: this makes it very hard to use the actual browser build in tests when e.g. running the node test runner - node always runs with the node condition, and there can only be additional ones added, but node itself cannot be removed.

So previously it was possible to run the browser build of React in a node testing environment with --condition=browser, and after this it will be impossible.

I'm gonna say: I'm not sure if it's relevant, but I wanted to add the thought to the conversation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the solution is to use mocking like

jest.mock('react-dom/server', () => require('react-dom/server.browser'))

@react-sizebot
Copy link

Comparing: f3e09d6...d220f69

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.66 kB 6.66 kB = 1.82 kB 1.82 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 497.80 kB 497.80 kB = 89.24 kB 89.24 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.67 kB 6.67 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 502.62 kB 502.62 kB = 89.94 kB 89.94 kB
facebook-www/ReactDOM-prod.classic.js = 597.04 kB 597.04 kB = 105.31 kB 105.31 kB
facebook-www/ReactDOM-prod.modern.js = 571.38 kB 571.38 kB = 101.25 kB 101.25 kB
test_utils/ReactAllWarnings.js Deleted 63.50 kB 0.00 kB Deleted 15.90 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
test_utils/ReactAllWarnings.js Deleted 63.50 kB 0.00 kB Deleted 15.90 kB 0.00 kB

Generated by 🚫 dangerJS against d220f69

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants