Skip to content

Feat react jsx #5131

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

Merged
merged 1 commit into from
Apr 1, 2021
Merged

Feat react jsx #5131

merged 1 commit into from
Apr 1, 2021

Conversation

jaysoo
Copy link
Member

@jaysoo jaysoo commented Mar 26, 2021

This PR changes the default runtime to automatic so the new JSX transform is used.

This change means users no longer need to import React from 'react'; in their component files.

Current Behavior

Uses "classic" runtime e.g. React.createElement

Expected Behavior

Uses "automatic" runtime e.g. _jsx(...) from 'react/jsx-runtime'

Related Issue(s)

Fixes #5090

Additional Information

  • Migrate existing tsconfig to use jsx: 'react-jsx' instead of jsx: 'react' (where applicable).
  • Migrate existing babelrc to use @emotion/babel-plugin instead of @emotion/babel-preset-css-prop (where applicable)
  • @nrwl/react:package will warn user if babelConfig is used -- it has been deprecated since Nx 10 -- we'll remove it in Nx 13.

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Mar 26, 2021

@jaysoo jaysoo force-pushed the feat-react-jsx branch 4 times, most recently from 4fd91dc to 1a501e0 Compare March 30, 2021 17:24
@jaysoo jaysoo marked this pull request as ready for review March 30, 2021 17:24
@jaysoo jaysoo force-pushed the feat-react-jsx branch 5 times, most recently from 28cc131 to e0e42a0 Compare March 31, 2021 17:47
@jaysoo jaysoo assigned jaysoo and unassigned jaysoo Mar 31, 2021
@jaysoo jaysoo force-pushed the feat-react-jsx branch 6 times, most recently from b181dcf to b42061f Compare April 1, 2021 01:49
'react/jsx-uses-vars': 'warn',
'react/no-danger-with-children': 'warn',
'react/no-direct-mutation-state': 'warn',
'react/no-is-mounted': 'warn',
'react/no-typos': 'error',
'react/react-in-jsx-scope': 'error',
'react/jsx-uses-react': 'off',
Copy link
Member Author

Choose a reason for hiding this comment

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

Turned off since we no longer need these rules.

@@ -422,7 +422,6 @@ describe('lib', () => {
outputPath: 'dist/libs/my-lib',
project: 'libs/my-lib/package.json',
tsConfig: 'libs/my-lib/tsconfig.lib.json',
babelConfig: '@nrwl/react/plugins/bundle-babel',
Copy link
Member Author

Choose a reason for hiding this comment

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

This is deprecated and we should not generate new libraries with this option.

@@ -17,6 +18,13 @@ describe('react:storybook-configuration', () => {
'@storybook/react': '^6.0.21',
},
});

jest.spyOn(logger, 'warn').mockImplementation(() => {});
Copy link
Member Author

Choose a reason for hiding this comment

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

Turning off warn and debug so the test output is clean.

@@ -29,6 +29,13 @@ describe('migrate-defaults-5-to-6 schematic', () => {
generateCypressSpecs: false,
generateStories: false,
});

jest.spyOn(logger, 'warn').mockImplementation(() => {});
Copy link
Member Author

Choose a reason for hiding this comment

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

Turning off warn and debug so the test output is clean.

@jaysoo jaysoo force-pushed the feat-react-jsx branch 3 times, most recently from e8e0f92 to e20e9d5 Compare April 1, 2021 01:59
@jaysoo jaysoo force-pushed the feat-react-jsx branch 2 times, most recently from 59c69cb to 74de523 Compare April 1, 2021 02:38
@jaysoo jaysoo requested a review from kirjai April 1, 2021 02:39
@jaysoo jaysoo assigned jaysoo and unassigned kirjai Apr 1, 2021
@jaysoo jaysoo force-pushed the feat-react-jsx branch 2 times, most recently from 988473a to 2fdd287 Compare April 1, 2021 02:52

// JSX spread is transformed into object spread in `@babel/plugin-transform-react-jsx`
// `useBuiltIns` will be removed in Babel 8.
if (presetOptions.runtime === 'automatic') {
Copy link
Contributor

Choose a reason for hiding this comment

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

since presetOptions.runtime is nullable, but reactPresetOptions.runtime is always set, should this be checking reactPresetOptions.runtime instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point, especially since we're not migrating their .babelrc to set runtime so we need to support it being undefined.

@jaysoo jaysoo enabled auto-merge (squash) April 1, 2021 13:40
@jaysoo jaysoo merged commit c84bbb3 into nrwl:master Apr 1, 2021
@jaysoo jaysoo deleted the feat-react-jsx branch April 1, 2021 14:13
@ptrhck
Copy link

ptrhck commented Apr 6, 2021

If I add a new library with nx g @nrwl/react:lib my-lib @ 11.6.1 it still creates a tsconfig with "jsx": "react". Am I missing something?

@kirjai
Copy link
Contributor

kirjai commented Apr 6, 2021

hey @ptrhck . this was merged after 11.6.1 was released. I believe the intention for this change is to be released in version 12, coming soon

@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

React 17 default to react-jsx in tsconfig
3 participants