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

Updates "@babel/preset-react" preset "runtime" param to "automatic" and cleans up import lines #325

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sagemintblue
Copy link

@sagemintblue sagemintblue commented Aug 9, 2024

While working through the Relay tutorial and its "newsfeed" example [1] I was confused by some seemingly unused import lines in tsx files of the following form:

import * as React from "react";

My VSCode configuration enables removal of unused imports when files are saved, so this line was being removed. This led to a runtime error of the form:

ReferenceError: React is not defined

Some searching lead me to the new JSX Transform announcement [2] which suggested that most of these React import lines are no longer needed. After further reading I found docs for the "@babel/preset-react" Babel preset [3] which suggest that the runtime parameter should be automatic (instead of classic, the default value) to ensure the functions that JSX transpiles to are automatically imported. This change did the trick for me. After cleaning up the import lines across most tsx files in the newsfeed project it still builds and runs without issue for me.

[1] https://relay.dev/docs/tutorial/intro/
[2] https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html
[3] https://babeljs.io/docs/babel-preset-react

@facebook-github-bot
Copy link

Hi @sagemintblue!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@sagemintblue sagemintblue changed the title Updates babel preset-react runtime to "automatic" and cleans up React import lines Updates "@babel/preset-react" preset "runtime" param to "automatic" and cleans up import lines Aug 9, 2024
@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@sagemintblue sagemintblue marked this pull request as ready for review August 9, 2024 00:55
@sagemintblue sagemintblue deleted the sagemintblue/clean_up_react_imports branch August 9, 2024 20:39
@sagemintblue sagemintblue restored the sagemintblue/clean_up_react_imports branch August 9, 2024 20:40
@sagemintblue sagemintblue reopened this Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants