Updates "@babel/preset-react" preset "runtime" param to "automatic" and cleans up import lines #325
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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:
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 beautomatic
(instead ofclassic
, 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