Open
Description
What kind of issue is this?
- React Compiler core (the JS output is incorrect, or your app works incorrectly after optimization)
- babel-plugin-react-compiler (build issue installing or using the Babel plugin)
- eslint-plugin-react-compiler (build issue installing or using the eslint plugin)
- react-compiler-healthcheck (build issue installing or using the healthcheck script)
Link to repro
https://stackblitz.com/edit/vitejs-vite-qlmehlcy?file=dist%2Fassets%2Findex-DL_BpHJl.js
Repro steps
I've written a babel plugin, which is used to minify matrix string values in SVG when building.
const matrixAttrs = {
feColorMatrix: ["values"],
feConvolveMatrix: ["kernelMatrix"],
feFuncR: ["tableValues"],
feFuncG: ["tableValues"],
feFuncB: ["tableValues"],
feFuncA: ["tableValues"],
};
export default (_babel) => {
return {
name: "babel-plugin-minify-svg-matrix",
visitor: {
JSXElement(path) {
const openingElement = path.node.openingElement;
const tagName = openingElement.name.name;
for (const [expectedTagName, expectedAttributes] of Object.entries(matrixAttrs)) {
if (tagName !== expectedTagName) continue;
for (const attribute of openingElement.attributes) {
if ("name" in attribute && expectedAttributes.includes(attribute.name.name) && attribute.value?.type === "StringLiteral") {
let value = attribute.value.value;
value = value.trim().replaceAll(/\s+/g, " ");
value = value.split(" ").map(n => n.replace(/^0+/, "").replace(/\.0*$/, "") || "0").join(" ");
attribute.value.value = value;
}
}
}
},
},
};
};
This is the code of the example component.
export default function App() {
return (
<svg>
<defs>
<filter>
<feColorMatrix
type="matrix"
values="
0.33 0.33 0.33 0 0
0.33 0.33 0.33 0 0
0.33 0.33 0.33 0 0
0 0 0 1 0
"
in="SourceGraphic"
result="colorMatrix"
/>
</filter>
</defs>
</svg>
);
}
When disable react compiler.
react({
babel: {
plugins: [
// ["babel-plugin-react-compiler", { target: "19" }],
minifySvgMatrix,
],
},
})
Build the project, and the bundled js minified the matrixes properly.
Then enable react compiler.
react({
babel: {
plugins: [
["babel-plugin-react-compiler", { target: "19" }],
minifySvgMatrix,
],
},
})
Build the project, and the minify SVG matrix babel plugin will not work.
Move react compiler after that plugin.
react({
babel: {
plugins: [
minifySvgMatrix,
["babel-plugin-react-compiler", { target: "19" }],
],
},
})
Same as above, still not work.
How often does this bug happen?
Every time
What version of React are you using?
19.1.0
What version of React Compiler are you using?
19.1.0-rc.2