diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-write-ref-prop-in-render.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-write-ref-prop-in-render.expect.md new file mode 100644 index 0000000000000..c00aaca4fe3a3 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-write-ref-prop-in-render.expect.md @@ -0,0 +1,27 @@ + +## Input + +```javascript +// @validateRefAccessDuringRender @compilationMode(infer) +function Component(props) { + const ref = props.ref; + ref.current = true; + return
{value}
; +} + +``` + + +## Error + +``` + 2 | function Component(props) { + 3 | const ref = props.ref; +> 4 | ref.current = true; + | ^^^^^^^^^^^ InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (4:4) + 5 | return
{value}
; + 6 | } + 7 | +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-write-ref-prop-in-render.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-write-ref-prop-in-render.js new file mode 100644 index 0000000000000..b939ea540bd13 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-write-ref-prop-in-render.js @@ -0,0 +1,6 @@ +// @validateRefAccessDuringRender @compilationMode(infer) +function Component(props) { + const ref = props.ref; + ref.current = true; + return
{value}
; +}