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 jsx-runtime and jsx-dev-runtime modules #18299

Merged
merged 1 commit into from Mar 17, 2020

Conversation

lunaruan
Copy link
Contributor

This PR adds the jsx-runtime and jsx-dev-runtime modules for the JSX Babel Plugin. WWW still relies on jsx/jsxs/jsxDEV from the "react" module, so once we refactor the code to point to the runtime modules we will remove jsx/jsxs/jsxDEV from the "react" module.

@facebook-github-bot facebook-github-bot added React Core Team Opened by a member of the React Core Team CLA Signed labels Mar 13, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 13, 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 ded98d8:

Sandbox Source
quirky-tdd-dws4b Configuration

@sizebot
Copy link

sizebot commented Mar 13, 2020

Details of bundled changes.

Comparing: 2666642...ded98d8

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js -4.9% -3.0% 108.97 KB 103.65 KB 26.03 KB 25.24 KB UMD_DEV
react-jsx-runtime.profiling.min.js n/a n/a 0 B 943 B 0 B 592 B NODE_PROFILING
react.production.min.js -3.5% -2.6% 12.66 KB 12.22 KB 4.87 KB 4.75 KB UMD_PROD
JSXRuntime-dev.js n/a n/a 0 B 29.41 KB 0 B 8.64 KB FB_WWW_DEV
react-jsx-dev-runtime.development.js n/a n/a 0 B 26.33 KB 0 B 8.08 KB NODE_DEV
react-jsx-dev-runtime.production.min.js n/a n/a 0 B 433 B 0 B 313 B NODE_PROD
react-jsx-dev-runtime.profiling.min.js n/a n/a 0 B 432 B 0 B 312 B NODE_PROFILING
JSXDEVRuntime-dev.js n/a n/a 0 B 28.82 KB 0 B 8.46 KB FB_WWW_DEV
JSXDEVRuntime-prod.js n/a n/a 0 B 510 B 0 B 343 B FB_WWW_PROD
react-jsx-runtime.development.js n/a n/a 0 B 26.91 KB 0 B 8.26 KB NODE_DEV
JSXDEVRuntime-profiling.js n/a n/a 0 B 510 B 0 B 343 B FB_WWW_PROFILING
react-jsx-runtime.production.min.js n/a n/a 0 B 944 B 0 B 593 B NODE_PROD
react.profiling.min.js -2.7% -1.6% 16.2 KB 15.76 KB 5.95 KB 5.85 KB UMD_PROFILING
JSXRuntime-prod.js n/a n/a 0 B 1.54 KB 0 B 742 B FB_WWW_PROD
react.development.js -7.2% -4.1% 70.39 KB 65.33 KB 18.27 KB 17.53 KB NODE_DEV
JSXRuntime-profiling.js n/a n/a 0 B 1.54 KB 0 B 742 B FB_WWW_PROFILING
react.production.min.js -5.9% -3.3% 7.73 KB 7.27 KB 2.97 KB 2.88 KB NODE_PROD
React-dev.js +17.6% +13.0% 75.59 KB 88.91 KB 19.11 KB 21.59 KB FB_WWW_DEV
React-prod.js -0.5% -1.3% 18.02 KB 17.92 KB 4.66 KB 4.6 KB FB_WWW_PROD
React-profiling.js -0.5% -1.3% 18.02 KB 17.92 KB 4.66 KB 4.6 KB FB_WWW_PROFILING

React: size: -3.5%, gzip: -2.6%

Size changes (experimental)

Generated by 🚫 dangerJS against ded98d8

@sizebot
Copy link

sizebot commented Mar 13, 2020

Details of bundled changes.

Comparing: 2666642...ded98d8

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js +0.1% +0.1% 100.31 KB 100.45 KB 24.65 KB 24.66 KB UMD_DEV
JSXRuntime-profiling.js n/a n/a 0 B 1.54 KB 0 B 742 B FB_WWW_PROFILING
JSXDEVRuntime-dev.js n/a n/a 0 B 28.83 KB 0 B 8.46 KB FB_WWW_DEV
JSXDEVRuntime-prod.js n/a n/a 0 B 510 B 0 B 343 B FB_WWW_PROD
JSXDEVRuntime-profiling.js n/a n/a 0 B 510 B 0 B 343 B FB_WWW_PROFILING
react-jsx-runtime.development.js n/a n/a 0 B 26.9 KB 0 B 8.25 KB NODE_DEV
react-jsx-runtime.production.min.js n/a n/a 0 B 931 B 0 B 585 B NODE_PROD
react-jsx-runtime.profiling.min.js n/a n/a 0 B 930 B 0 B 584 B NODE_PROFILING
JSXRuntime-dev.js n/a n/a 0 B 29.41 KB 0 B 8.64 KB FB_WWW_DEV
JSXRuntime-prod.js n/a n/a 0 B 1.54 KB 0 B 742 B FB_WWW_PROD
react.development.js +0.2% +0.1% 62.14 KB 62.28 KB 16.92 KB 16.94 KB NODE_DEV
React-dev.js +17.5% +12.7% 76.26 KB 89.58 KB 19.28 KB 21.73 KB FB_WWW_DEV
React-prod.js -0.5% -1.0% 18.08 KB 17.98 KB 4.67 KB 4.62 KB FB_WWW_PROD
react-jsx-dev-runtime.development.js n/a n/a 0 B 26.32 KB 0 B 8.08 KB NODE_DEV
React-profiling.js -0.5% -1.0% 18.08 KB 17.98 KB 4.67 KB 4.62 KB FB_WWW_PROFILING
react-jsx-dev-runtime.production.min.js n/a n/a 0 B 420 B 0 B 304 B NODE_PROD
react-jsx-dev-runtime.profiling.min.js n/a n/a 0 B 419 B 0 B 304 B NODE_PROFILING

Size changes (stable)

Generated by 🚫 dangerJS against ded98d8

@@ -34,6 +35,7 @@ describe('ReactElement.jsx', () => {
ReactFeatureFlags.warnAboutSpreadingKeyToJSX = true;
Copy link
Collaborator

@gaearon gaearon Mar 13, 2020

Choose a reason for hiding this comment

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

If this test wasn't marked as "internal", it would fail on bundles as it should — because we haven't exposed these entry points on npm. To do that, check out how files in npm/ folders in different packages work. Also note "files" array in package.json of each package. (Oops, you have that part — but still need npm entry points.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

Need to add npm entry points.

@gaearon
Copy link
Collaborator

gaearon commented Mar 13, 2020

You'll also need to add them to bundles.js to actually build the bundles. See similar entry points (e.g. react-dom/server and its config) for expiration. Hit me up for any questions!

@gaearon
Copy link
Collaborator

gaearon commented Mar 13, 2020

Pls rebase :-) I think this should fail now.

@lunaruan lunaruan force-pushed the jsx-runtime branch 3 times, most recently from 88ea8d9 to 9565d1b Compare March 13, 2020 23:05
Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

lg, pending CI, nits and a decision on UMD bundles.

Note that if we merge this now, the next release will go out with these entry points. Are we ready in terms of final naming, bundles, etc?

scripts/rollup/bundles.js Outdated Show resolved Hide resolved
scripts/rollup/bundles.js Outdated Show resolved Hide resolved
scripts/rollup/bundles.js Outdated Show resolved Hide resolved
scripts/rollup/forks.js Outdated Show resolved Hide resolved
scripts/rollup/forks.js Outdated Show resolved Hide resolved
@lunaruan lunaruan force-pushed the jsx-runtime branch 2 times, most recently from ef6fb14 to a5aa16e Compare March 13, 2020 23:25
@@ -29,6 +30,7 @@ describe('ReactElement.jsx', () => {
global.Symbol = undefined;

React = require('react');
jsxRuntime = require('react/jsx-runtime');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Super nit: JSXRuntime in tests for capitalization consistency? I don't care tho

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

Okay as we figured out, we still have an issue with duplication of bundle content.

What we need to do is to remove jsx from the React object completely, and to create separate entry points for both runtimes. Like src/jsx/JSXRuntime. There you can put the jsx() implementation with the minimal copy paste it needs (ReactElement) and an import of the current owner from React. Note you can’t just import it from parent folder. You need to get it from require(“react”) like all other packages do. Because otherwise we’ll get a copy of it in our bundle.

Then for FB bundle if we want to keep React.jsx working for a bit you could do this in the FB index file I think. Just re export from both React and Runtime.

scripts/rollup/forks.js Outdated Show resolved Hide resolved
@@ -29,6 +31,9 @@
"loose-envify": "^1.1.0",
"object-assign": "^4.1.1"
},
"peerDependencies": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A package can't be its own peer. This isn't needed. If our scripts complain it's our scripts that should be fixed.

@lunaruan lunaruan force-pushed the jsx-runtime branch 3 times, most recently from 249203e to 2b03ad8 Compare March 17, 2020 00:59
packages/react/src/React.js Outdated Show resolved Hide resolved
@jetro4u
Copy link

jetro4u commented Aug 9, 2021

I am using the 0.0.0-experimental-f42431abe version of React for testing. I converted a version 17 App and on all the pages I am getting the React' must be in scope when using JSX error. Meanwhile I already follow the Introducing the New JSX Transform tutorial to implement it. Is it that the the New JSX Transform is not available in the experimental version? Or is there a way to implement it?

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.

None yet

7 participants