From 8912702a00f0ec2d8e2a4f5b97e46a02ce1b4e4d Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Fri, 15 Nov 2024 15:37:27 -0800 Subject: [PATCH] [compiler] Fixture for non-exhaustive effect deps ghstack-source-id: 7da27fb09d056829d87c441d29df30194de1d0c6 Pull Request resolved: https://github.com/facebook/react/pull/31559 --- ....todo-non-exhaustive-effect-deps.expect.md | 36 +++++++++++++++++++ .../error.todo-non-exhaustive-effect-deps.js | 15 ++++++++ 2 files changed, 51 insertions(+) create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-non-exhaustive-effect-deps.expect.md create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-non-exhaustive-effect-deps.js diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-non-exhaustive-effect-deps.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-non-exhaustive-effect-deps.expect.md new file mode 100644 index 0000000000..ccf277d30d --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-non-exhaustive-effect-deps.expect.md @@ -0,0 +1,36 @@ + +## Input + +```javascript +import {logValue} from 'shared-runtime'; + +function Component({a}) { + useEffect(() => { + logValue(a); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + return null; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{a: 0}], + sequentialRenders: [{a: 1}], +}; + +``` + + +## Error + +``` + 4 | useEffect(() => { + 5 | logValue(a); +> 6 | // eslint-disable-next-line react-hooks/exhaustive-deps + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ InvalidReact: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. eslint-disable-next-line react-hooks/exhaustive-deps (6:6) + 7 | }, []); + 8 | return null; + 9 | } +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-non-exhaustive-effect-deps.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-non-exhaustive-effect-deps.js new file mode 100644 index 0000000000..ff1f271fa3 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-non-exhaustive-effect-deps.js @@ -0,0 +1,15 @@ +import {logValue} from 'shared-runtime'; + +function Component({a}) { + useEffect(() => { + logValue(a); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + return null; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{a: 0}], + sequentialRenders: [{a: 1}], +};