fix: potential null dereference in react compiler configuration (#32571)#36163
fix: potential null dereference in react compiler configuration (#32571)#36163zendy199x wants to merge 1 commit intofacebook:mainfrom
Conversation
The babel.config-react-compiler.js file contains a hack comment about Zod spreading values in React Compiler's build artifact. If the baseConfig.plugins array is null or undefined, the assignment `plugins: baseConfig.plugins` will cause a runtime TypeError when the compiler tries to process the configuration. This could crash the build process or cause incorrect transpilation. Signed-off-by: Zendy <50132805+zendy199x@users.noreply.github.com>
|
Hi @zendy199x! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
There was a problem hiding this comment.
Pull request overview
This PR adjusts the React Compiler Babel config used for transforming the compiler’s build artifact during Jest runs, ensuring the exported plugins field is always an array to avoid runtime failures when baseConfig.plugins is missing or invalid.
Changes:
- Guard
pluginsinbabel.config-react-compiler.jswith anArray.isArraycheck and default to[].
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| module.exports = { | ||
| plugins: baseConfig.plugins, | ||
| plugins: Array.isArray(baseConfig.plugins) ? baseConfig.plugins : [], |
There was a problem hiding this comment.
This fallback will silently drop plugins if baseConfig.plugins is anything other than an array (e.g. a function/object due to a future change), which could lead to the compiler artifact being transformed incorrectly while tests still run. Consider only defaulting for null/undefined and throwing a clear error for other unexpected types so misconfiguration fails fast with a helpful message.
|
|
||
| module.exports = { | ||
| plugins: baseConfig.plugins, | ||
| plugins: Array.isArray(baseConfig.plugins) ? baseConfig.plugins : [], |
There was a problem hiding this comment.
PR description mentions crashing the build process, but this config appears to be used only by Jest (see scripts/jest/config.base.js transform for the compiler dist file). Consider updating the PR summary/testing notes to reflect that the impact is on local/test transforms rather than the production build, unless there are other consumers not found in-repo.
|
I took another pass at the failing CI checks, but after 1 follow-up attempt(s) these checks are still failing: Cleanup artifacts. I'm closing this PR for now because the remaining failures look like they need manual investigation before the change can move forward. |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Fixes #32571
Summary
Fix potential null dereference in React Compiler configuration by adding a null check for the plugins array.
The babel.config-react-compiler.js file contains a hack comment about Zod spreading values in React Compiler's build artifact. If the baseConfig.plugins array is null or undefined, the assignment
plugins: baseConfig.pluginswill cause a runtime TypeError when the compiler tries to process the configuration. This could crash the build process or cause incorrect transpilation.How did you test this change?