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
Merged

Conversation

@lunaruan
Copy link
Contributor

@lunaruan lunaruan commented Mar 13, 2020

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.

@codesandbox
Copy link

@codesandbox codesandbox 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 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 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;

This comment has been minimized.

@gaearon

gaearon Mar 13, 2020
Member

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

This comment has been minimized.

Copy link
Member

@gaearon gaearon left a comment

Need to add npm entry points.

@gaearon
Copy link
Member

@gaearon 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
Member

@gaearon gaearon commented Mar 13, 2020

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

@lunaruan lunaruan force-pushed the lunaruan:jsx-runtime branch 3 times, most recently from 88ea8d9 to 9565d1b Mar 13, 2020
Copy link
Member

@gaearon gaearon left a comment

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 lunaruan:jsx-runtime branch 2 times, most recently from ef6fb14 to a5aa16e Mar 13, 2020
@@ -29,6 +30,7 @@ describe('ReactElement.jsx', () => {
global.Symbol = undefined;

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

This comment has been minimized.

@gaearon

gaearon Mar 13, 2020
Member

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

Copy link
Member

@gaearon gaearon left a comment

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
@lunaruan lunaruan force-pushed the lunaruan:jsx-runtime branch from a5aa16e to 4dbbbcb Mar 17, 2020
@@ -29,6 +31,9 @@
"loose-envify": "^1.1.0",
"object-assign": "^4.1.1"
},
"peerDependencies": {

This comment has been minimized.

@gaearon

gaearon Mar 17, 2020
Member

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 lunaruan:jsx-runtime branch 3 times, most recently from 249203e to 2b03ad8 Mar 17, 2020
packages/react/src/React.js Outdated Show resolved Hide resolved
@lunaruan lunaruan force-pushed the lunaruan:jsx-runtime branch from 2b03ad8 to c076560 Mar 17, 2020
packages/react/index.js Outdated Show resolved Hide resolved
@lunaruan lunaruan force-pushed the lunaruan:jsx-runtime branch from c076560 to 31c5847 Mar 17, 2020
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

This comment has been minimized.

@gaearon

gaearon Mar 17, 2020
Member

Would be nice to have @flow on this. Not blocking though because we didn't have it before either.

This comment has been minimized.

@lunaruan

lunaruan Mar 17, 2020
Author Contributor

I can do this in a separate PR after landing the Babel transform!

Copy link
Member

@gaearon gaearon left a comment

Seems legit. Please inspect the bundles manually, especially the ones in build/node_modules. You can run yarn build react/ --pretty to make the output readable.

@lunaruan lunaruan force-pushed the lunaruan:jsx-runtime branch from 31c5847 to ded98d8 Mar 17, 2020
@lunaruan lunaruan merged commit 90f8fe6 into facebook:master Mar 17, 2020
31 checks passed
31 checks passed
ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: build_devtools_and_process_artifacts Your tests passed on CircleCI!
Details
ci/circleci: build_experimental Your tests passed on CircleCI!
Details
ci/circleci: flow Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
ci/circleci: lint_build 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 Your tests passed on CircleCI!
Details
ci/circleci: sizebot_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_build Your tests passed on CircleCI!
Details
ci/circleci: test_build_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_build_prod Your tests passed on CircleCI!
Details
ci/circleci: test_build_prod_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_devtools Your tests passed on CircleCI!
Details
ci/circleci: test_dom_fixtures Your tests passed on CircleCI!
Details
ci/circleci: test_source Your tests passed on CircleCI!
Details
ci/circleci: test_source_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_source_persistent Your tests passed on CircleCI!
Details
ci/circleci: test_source_prod Your tests passed on CircleCI!
Details
ci/circleci: test_source_prod_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_source_www Your tests passed on CircleCI!
Details
ci/circleci: test_source_www_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_source_www_prod Your tests passed on CircleCI!
Details
ci/circleci: test_source_www_prod_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_source_www_variant Your tests passed on CircleCI!
Details
ci/circleci: test_source_www_variant_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_source_www_variant_prod Your tests passed on CircleCI!
Details
ci/circleci: test_source_www_variant_prod_experimental Your tests passed on CircleCI!
Details
ci/codesandbox Building packages succeeded.
Details
@lunaruan lunaruan deleted the lunaruan:jsx-runtime branch Mar 17, 2020
@midudev
Copy link

@midudev midudev commented Mar 25, 2020

Hi 👋 I thought this change would land with the next version but I see it's not yet available. Do you have any idea when this will be available? Thanks! 🙇

@gaearon
Copy link
Member

@gaearon gaearon commented Mar 25, 2020

@midudev Can you clarify why you need it?

@midudev
Copy link

@midudev midudev commented Mar 25, 2020

Thanks for the reply. Yes, trying to get working latest babel-preset-react with automatic runtime, I'm getting this error:

Module not found: Can't resolve 'react/jsx-runtime' in '/Users/midudev/Dev/frontend-fc--web-server/src'

I thought it was related to this PR as installing latest react version there's no jsx-runtime available to import. Maybe am I doing something wrong?

@gaearon
Copy link
Member

@gaearon gaearon commented Mar 25, 2020

Right, I just wanted to confirm why you're asking. This indeed hasn't been released in stable yet. You can install react@experimental if you want, that one has it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.