Skip to content

Commit bbdd01d

Browse files
committed
Update on "[compiler] Errors in earlier functions dont stop subsequent compilation"
Errors in an earlier component/hook shouldn't stop later components from compiling. [ghstack-poisoned]
2 parents 35488e7 + f8cc8f1 commit bbdd01d

File tree

26 files changed

+43
-75
lines changed

26 files changed

+43
-75
lines changed

compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ export enum ErrorSeverity {
1818
* Code that breaks the rules of React.
1919
*/
2020
InvalidReact = 'InvalidReact',
21-
/**
22-
* Like InvalidReact, but this specific error is still in testing w some false positives
23-
* so we special-case it to suppress in ESLint.
24-
*/
25-
InvalidRefInRender = 'InvalidRefInRender',
2621
/**
2722
* Incorrect configuration of the compiler.
2823
*/
@@ -237,7 +232,6 @@ export class CompilerError extends Error {
237232
case ErrorSeverity.InvalidJS:
238233
case ErrorSeverity.InvalidReact:
239234
case ErrorSeverity.InvalidConfig:
240-
case ErrorSeverity.InvalidRefInRender:
241235
return true;
242236
case ErrorSeverity.CannotPreserveMemoization:
243237
case ErrorSeverity.Todo:

compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoRefAccesInRender.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ function validateNoRefAccessInRenderImpl(
246246
// Report a more precise error when calling a local function that accesses a ref
247247
if (state.refAccessingFunctions.has(callee.identifier.id)) {
248248
errors.push({
249-
severity: ErrorSeverity.InvalidRefInRender,
249+
severity: ErrorSeverity.InvalidReact,
250250
reason:
251251
'This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef)',
252252
loc: callee.loc,
@@ -351,7 +351,7 @@ function validateNoRefValueAccess(
351351
state.refAccessingFunctions.has(operand.identifier.id)
352352
) {
353353
errors.push({
354-
severity: ErrorSeverity.InvalidRefInRender,
354+
severity: ErrorSeverity.InvalidReact,
355355
reason:
356356
'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)',
357357
loc: state.refValues.get(operand.identifier.id) ?? operand.loc,
@@ -377,7 +377,7 @@ function validateNoRefAccess(
377377
state.refAccessingFunctions.has(operand.identifier.id)
378378
) {
379379
errors.push({
380-
severity: ErrorSeverity.InvalidRefInRender,
380+
severity: ErrorSeverity.InvalidReact,
381381
reason:
382382
'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)',
383383
loc: loc,
@@ -398,7 +398,7 @@ function validateNoDirectRefValueAccess(
398398
): void {
399399
if (state.refValues.has(operand.identifier.id)) {
400400
errors.push({
401-
severity: ErrorSeverity.InvalidRefInRender,
401+
severity: ErrorSeverity.InvalidReact,
402402
reason:
403403
'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)',
404404
loc: state.refValues.get(operand.identifier.id) ?? operand.loc,

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.capture-ref-for-later-mutation.expect.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ export const FIXTURE_ENTRYPOINT = {
3535
10 | };
3636
11 | const moveLeft = {
3737
> 12 | handler: handleKey('left'),
38-
| ^^^^^^^^^ InvalidRefInRender: This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef) (12:12)
38+
| ^^^^^^^^^ InvalidReact: This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef) (12:12)
3939
40-
InvalidRefInRender: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (12:12)
40+
InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (12:12)
4141
42-
InvalidRefInRender: This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef) (15:15)
42+
InvalidReact: This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef) (15:15)
4343
44-
InvalidRefInRender: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (15:15)
44+
InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (15:15)
4545
13 | };
4646
14 | const moveRight = {
4747
15 | handler: handleKey('right'),

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-access-ref-during-render.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Component(props) {
1818
2 | function Component(props) {
1919
3 | const ref = useRef(null);
2020
> 4 | const value = ref.current;
21-
| ^^^^^^^^^^^ InvalidRefInRender: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (4:4)
21+
| ^^^^^^^^^^^ InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (4:4)
2222
5 | return value;
2323
6 | }
2424
7 |

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-aliased-ref-in-callback-invoked-during-render-.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function Component(props) {
2222
7 | return <Foo item={item} current={current} />;
2323
8 | };
2424
> 9 | return <Items>{props.items.map(item => renderItem(item))}</Items>;
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^ InvalidRefInRender: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (9:9)
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^ InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (9:9)
2626
10 | }
2727
11 |
2828
```

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-disallow-mutating-ref-in-render.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function Component() {
1919
2 | function Component() {
2020
3 | const ref = useRef(null);
2121
> 4 | ref.current = false;
22-
| ^^^^^^^^^^^ InvalidRefInRender: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (4:4)
22+
| ^^^^^^^^^^^ InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (4:4)
2323
5 |
2424
6 | return <button ref={ref} />;
2525
7 | }

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-disallow-mutating-refs-in-render-transitive.expect.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ function Component() {
2424
7 | };
2525
8 | const changeRef = setRef;
2626
> 9 | changeRef();
27-
| ^^^^^^^^^ InvalidRefInRender: This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef) (9:9)
27+
| ^^^^^^^^^ InvalidReact: This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef) (9:9)
2828
29-
InvalidRefInRender: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (9:9)
29+
InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (9:9)
3030
10 |
3131
11 | return <button ref={ref} />;
3232
12 | }

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-pass-ref-to-function.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Component(props) {
1818
2 | function Component(props) {
1919
3 | const ref = useRef(null);
2020
> 4 | const x = foo(ref);
21-
| ^^^ InvalidRefInRender: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (4:4)
21+
| ^^^ InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (4:4)
2222
5 | return x.current;
2323
6 | }
2424
7 |

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-read-ref-prop-in-render-destructure.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function Component({ref}) {
1717
1 | // @validateRefAccessDuringRender @compilationMode(infer)
1818
2 | function Component({ref}) {
1919
> 3 | const value = ref.current;
20-
| ^^^^^^^^^^^ InvalidRefInRender: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (3:3)
20+
| ^^^^^^^^^^^ InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (3:3)
2121
4 | return <div>{value}</div>;
2222
5 | }
2323
6 |

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-read-ref-prop-in-render-property-load.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function Component(props) {
1717
1 | // @validateRefAccessDuringRender @compilationMode(infer)
1818
2 | function Component(props) {
1919
> 3 | const value = props.ref.current;
20-
| ^^^^^^^^^^^^^^^^^ InvalidRefInRender: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (3:3)
20+
| ^^^^^^^^^^^^^^^^^ InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (3:3)
2121
4 | return <div>{value}</div>;
2222
5 | }
2323
6 |

0 commit comments

Comments
 (0)