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

Improve error message when not providing a value for JSX key #12983

Merged
merged 4 commits into from Mar 16, 2021

Conversation

hbendev
Copy link
Contributor

@hbendev hbendev commented Mar 8, 2021

Q                       A
Fixed Issues? Fixes #12931
Patch: Bug Fix? No
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link -
Any Dependency Changes? None
License MIT

Throwing a more descriptive error when compiling a React element in a list that hasn't been given a value for its key.
eg. <Component key />

@babel-bot
Copy link
Collaborator

babel-bot commented Mar 9, 2021

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/44294/

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 9, 2021

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 d0c94e1:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@nicolo-ribaudo nicolo-ribaudo added the PR: Polish 💅 A type of pull request used for our changelog categories label Mar 9, 2021
@@ -0,0 +1,2 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you duplicate this test to fixtures/react/, which shares test suites with react-automatic but with runtime set to classic, the default behaviour of Babel 7.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I've done that. As I mentioned in the issue, the compilation was successful in development mode. Fixing it was a bit trickier. Let me know if I have to improve my solution in any way.

hbendev and others added 3 commits March 10, 2021 21:16
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

We should also throw in development mode, but let's merge this as-is for now since it already fixes the original problem (the unhelpful error message).

If you want to open the follow-up PR please do so, otherwise I'll open an issue about it!

@nicolo-ribaudo nicolo-ribaudo changed the title Improve error message when not providing a value for key Improve error message when not providing a value for JSX key Mar 16, 2021
@nicolo-ribaudo nicolo-ribaudo merged commit 281acd6 into babel:main Mar 16, 2021
@yedidyak
Copy link

This changed the behaviour very slightly, and actually ended up breaking a build of ours. Now when running the react-native metro bundler on an error case of 'key' used as a boolean it throws an exception and fails at compile time, instead of at runtime.

We fixed it by fixing the bug, but maybe worth checking this scenario in future.

Thanks for working on amazing open source anyway!

@nicolo-ribaudo
Copy link
Member

Oh sorry for the inconvenience, I assumed this was already a compile-time error (just with a worse message) because of #12931.

If many people are affected we could make it a warning instead, but since this would be a runtime error anyway I lean towards leaving it as-is.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jun 24, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: errors area: react outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Polish 💅 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(plugin-transform-react-jsx): Compile error, when element's JSXAttribute key isn't given a value
6 participants