You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improves the error message for ValidateNoRefAccessInRender, using the new diagnostic type as well as providing a longer but succinct summary of what refs are for and why they're unsafe to access in render.
Copy file name to clipboardExpand all lines: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.capture-ref-for-mutation.expect.md
Error: This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef)
37
+
Error: Cannot access refs during render
38
38
39
-
error.capture-ref-for-mutation.ts:12:13
40
-
10 | };
41
-
11 | const moveLeft = {
42
-
> 12 | handler: handleKey('left')(),
43
-
| ^^^^^^^^^^^^^^^^^ This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef)
44
-
13 | };
45
-
14 | const moveRight = {
46
-
15 | handler: handleKey('right')(),
47
-
48
-
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
39
+
React refs are values that are not needed for rendering. Refs should only be accessed outside of render, such as in event handlers or effects. Accessing a ref value (the `current` property) during render can cause your component not to update as expected (https://react.dev/reference/react/useRef)
49
40
50
41
error.capture-ref-for-mutation.ts:12:13
51
42
10 | };
52
43
11 | const moveLeft = {
53
44
> 12 | handler: handleKey('left')(),
54
-
| ^^^^^^^^^^^^^^^^^ Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
45
+
| ^^^^^^^^^^^^^^^^^ This function accesses a ref value
55
46
13 | };
56
47
14 | const moveRight = {
57
48
15 | handler: handleKey('right')(),
58
49
59
-
Error: This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef)
60
-
61
-
error.capture-ref-for-mutation.ts:15:13
62
-
13 | };
63
-
14 | const moveRight = {
64
-
> 15 | handler: handleKey('right')(),
65
-
| ^^^^^^^^^^^^^^^^^^ This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef)
66
-
16 | };
67
-
17 | return [moveLeft, moveRight];
68
-
18 | }
50
+
Error: Cannot access refs during render
69
51
70
-
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
52
+
React refs are values that are not needed for rendering. Refs should only be accessed outside of render, such as in event handlers or effects. Accessing a ref value (the `current` property) during render can cause your component not to update as expected (https://react.dev/reference/react/useRef)
71
53
72
54
error.capture-ref-for-mutation.ts:15:13
73
55
13 | };
74
56
14 | const moveRight = {
75
57
> 15 | handler: handleKey('right')(),
76
-
| ^^^^^^^^^^^^^^^^^^ Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
58
+
| ^^^^^^^^^^^^^^^^^^ This function accesses a ref value
Copy file name to clipboardExpand all lines: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.hook-ref-value.expect.md
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
25
+
Error: Cannot access refs during render
26
+
27
+
React refs are values that are not needed for rendering. Refs should only be accessed outside of render, such as in event handlers or effects. Accessing a ref value (the `current` property) during render can cause your component not to update as expected (https://react.dev/reference/react/useRef)
26
28
27
29
error.hook-ref-value.ts:5:23
28
30
3 | function Component(props) {
29
31
4 | const ref = useRef();
30
32
> 5 | useEffect(() => {}, [ref.current]);
31
-
| ^^^^^^^^^^^ Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
33
+
| ^^^^^^^^^^^ Cannot access ref value during render
32
34
6 | }
33
35
7 |
34
36
8 | export const FIXTURE_ENTRYPOINT = {
35
37
36
-
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
38
+
Error: Cannot access refs during render
39
+
40
+
React refs are values that are not needed for rendering. Refs should only be accessed outside of render, such as in event handlers or effects. Accessing a ref value (the `current` property) during render can cause your component not to update as expected (https://react.dev/reference/react/useRef)
37
41
38
42
error.hook-ref-value.ts:5:23
39
43
3 | function Component(props) {
40
44
4 | const ref = useRef();
41
45
> 5 | useEffect(() => {}, [ref.current]);
42
-
| ^^^^^^^^^^^ Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
46
+
| ^^^^^^^^^^^ Cannot access ref value during render
Copy file name to clipboardExpand all lines: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-access-ref-during-render.expect.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,13 +17,15 @@ function Component(props) {
17
17
```
18
18
Found 1 error:
19
19
20
-
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
20
+
Error: Cannot access refs during render
21
+
22
+
React refs are values that are not needed for rendering. Refs should only be accessed outside of render, such as in event handlers or effects. Accessing a ref value (the `current` property) during render can cause your component not to update as expected (https://react.dev/reference/react/useRef)
21
23
22
24
error.invalid-access-ref-during-render.ts:4:16
23
25
2 | function Component(props) {
24
26
3 | const ref = useRef(null);
25
27
> 4 | const value = ref.current;
26
-
| ^^^^^^^^^^^ Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
28
+
| ^^^^^^^^^^^ Cannot access ref value during render
Copy file name to clipboardExpand all lines: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-aliased-ref-in-callback-invoked-during-render-.expect.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,13 +21,15 @@ function Component(props) {
21
21
```
22
22
Found 1 error:
23
23
24
-
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
24
+
Error: Cannot access refs during render
25
+
26
+
React refs are values that are not needed for rendering. Refs should only be accessed outside of render, such as in event handlers or effects. Accessing a ref value (the `current` property) during render can cause your component not to update as expected (https://react.dev/reference/react/useRef)
Copy file name to clipboardExpand all lines: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-assign-current-inferred-ref-during-render.expect.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,12 +20,14 @@ component Example() {
20
20
```
21
21
Found 1 error:
22
22
23
-
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
23
+
Error: Cannot access refs during render
24
+
25
+
React refs are values that are not needed for rendering. Refs should only be accessed outside of render, such as in event handlers or effects. Accessing a ref value (the `current` property) during render can cause your component not to update as expected (https://react.dev/reference/react/useRef)
24
26
25
27
4 | component Example() {
26
28
5 | const fooRef = makeObject_Primitives();
27
29
> 6 | fooRef.current = true;
28
-
| ^^^^^^^^^^^^^^ Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
Copy file name to clipboardExpand all lines: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-disallow-mutating-ref-in-render.expect.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,13 +18,15 @@ function Component() {
18
18
```
19
19
Found 1 error:
20
20
21
-
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
21
+
Error: Cannot access refs during render
22
+
23
+
React refs are values that are not needed for rendering. Refs should only be accessed outside of render, such as in event handlers or effects. Accessing a ref value (the `current` property) during render can cause your component not to update as expected (https://react.dev/reference/react/useRef)
0 commit comments