Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae3c5a707f |
@@ -348,7 +348,7 @@ function processInstruction(
|
||||
if (isTopLevel) {
|
||||
// Direct mutation at top level - error immediately
|
||||
errors.pushDiagnostic(
|
||||
makeRefMutationError(mutation.place, mutation.isCurrentProperty),
|
||||
makeRefMutationError(mutation.place),
|
||||
);
|
||||
}
|
||||
return mutation;
|
||||
@@ -366,7 +366,7 @@ function processInstruction(
|
||||
if (mutationInfo != null && isTopLevel) {
|
||||
// Calling a ref-mutating function at top level - error
|
||||
errors.pushDiagnostic(
|
||||
makeRefMutationError(mutationInfo.place, mutationInfo.isCurrentProperty),
|
||||
makeRefMutationError(mutationInfo.place),
|
||||
);
|
||||
}
|
||||
break;
|
||||
@@ -397,33 +397,20 @@ function processInstruction(
|
||||
return null;
|
||||
}
|
||||
|
||||
function makeRefMutationError(
|
||||
place: Place,
|
||||
isCurrentProperty: boolean,
|
||||
): CompilerDiagnostic {
|
||||
const diagnostic = CompilerDiagnostic.create({
|
||||
function makeRefMutationError(place: Place): CompilerDiagnostic {
|
||||
return CompilerDiagnostic.create({
|
||||
category: ErrorCategory.Refs,
|
||||
reason: 'Mutating refs during render is not allowed',
|
||||
reason: 'Cannot access refs during render',
|
||||
description: REF_ERROR_DESCRIPTION,
|
||||
}).withDetails({
|
||||
kind: 'error',
|
||||
loc: place.loc,
|
||||
message: 'Cannot mutate ref during render',
|
||||
message: 'Cannot update ref during render',
|
||||
});
|
||||
|
||||
if (isCurrentProperty) {
|
||||
diagnostic.withDetails({
|
||||
kind: 'hint',
|
||||
message:
|
||||
'Refs may be mutated during render if initialized with `if (ref.current == null)`',
|
||||
});
|
||||
}
|
||||
|
||||
return diagnostic;
|
||||
}
|
||||
|
||||
export const REF_ERROR_DESCRIPTION =
|
||||
'React refs are mutable containers that should only be mutated outside of render, ' +
|
||||
'such as in event handlers or effects. Mutating a ref during render can cause ' +
|
||||
'bugs because the mutation may not be associated with a particular render. ' +
|
||||
'See https://react.dev/reference/react/useRef';
|
||||
'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,7 +24,7 @@ Found 1 error:
|
||||
|
||||
Error: Cannot access ref value during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.hook-ref-value.ts:5:22
|
||||
3 | function Component(props) {
|
||||
|
||||
@@ -19,7 +19,7 @@ Found 1 error:
|
||||
|
||||
Error: Cannot access ref value during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.invalid-access-ref-during-render.ts:5:9
|
||||
3 | const ref = useRef(null);
|
||||
|
||||
@@ -23,7 +23,7 @@ Found 1 error:
|
||||
|
||||
Error: Cannot access ref value during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.invalid-aliased-ref-in-callback-invoked-during-render-.ts:7:37
|
||||
5 | const aliasedRef = ref;
|
||||
|
||||
@@ -20,19 +20,17 @@ component Example() {
|
||||
```
|
||||
Found 1 error:
|
||||
|
||||
Error: Mutating refs during render is not allowed
|
||||
Error: Cannot access refs during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
4 | component Example() {
|
||||
5 | const fooRef = makeObject_Primitives();
|
||||
> 6 | fooRef.current = true;
|
||||
| ^^^^^^ Cannot mutate ref during render
|
||||
| ^^^^^^ Cannot update ref during render
|
||||
7 |
|
||||
8 | return <Stringify foo={fooRef} />;
|
||||
9 | }
|
||||
|
||||
Refs may be mutated during render if initialized with `if (ref.current == null)`
|
||||
```
|
||||
|
||||
|
||||
@@ -18,20 +18,18 @@ function Component() {
|
||||
```
|
||||
Found 1 error:
|
||||
|
||||
Error: Mutating refs during render is not allowed
|
||||
Error: Cannot access refs during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.invalid-disallow-mutating-ref-in-render.ts:4:2
|
||||
2 | function Component() {
|
||||
3 | const ref = useRef(null);
|
||||
> 4 | ref.current = false;
|
||||
| ^^^ Cannot mutate ref during render
|
||||
| ^^^ Cannot update ref during render
|
||||
5 |
|
||||
6 | return <button ref={ref} />;
|
||||
7 | }
|
||||
|
||||
Refs may be mutated during render if initialized with `if (ref.current == null)`
|
||||
```
|
||||
|
||||
|
||||
@@ -23,20 +23,18 @@ function Component() {
|
||||
```
|
||||
Found 1 error:
|
||||
|
||||
Error: Mutating refs during render is not allowed
|
||||
Error: Cannot access refs during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.invalid-disallow-mutating-refs-in-render-transitive.ts:6:4
|
||||
4 |
|
||||
5 | const setRef = () => {
|
||||
> 6 | ref.current = false;
|
||||
| ^^^ Cannot mutate ref during render
|
||||
| ^^^ Cannot update ref during render
|
||||
7 | };
|
||||
8 | const changeRef = setRef;
|
||||
9 | changeRef();
|
||||
|
||||
Refs may be mutated during render if initialized with `if (ref.current == null)`
|
||||
```
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ Found 1 error:
|
||||
|
||||
Error: Cannot access ref value during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.invalid-read-ref-prop-in-render-destructure.ts:4:15
|
||||
2 | function Component({ref}) {
|
||||
|
||||
@@ -18,7 +18,7 @@ Found 1 error:
|
||||
|
||||
Error: Cannot access ref value during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.invalid-read-ref-prop-in-render-property-load.ts:4:15
|
||||
2 | function Component(props) {
|
||||
|
||||
@@ -26,7 +26,7 @@ Found 1 error:
|
||||
|
||||
Error: Cannot access ref value during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
5 | const r = useRef(null);
|
||||
6 | const current = !r.current;
|
||||
|
||||
@@ -22,7 +22,7 @@ Found 1 error:
|
||||
|
||||
Error: Cannot access ref value during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.invalid-ref-in-callback-invoked-during-render.ts:6:37
|
||||
4 | const renderItem = item => {
|
||||
|
||||
@@ -25,19 +25,17 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
```
|
||||
Found 1 error:
|
||||
|
||||
Error: Mutating refs during render is not allowed
|
||||
Error: Cannot access refs during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
5 | const r = useRef(null);
|
||||
6 | if (!r.current) {
|
||||
> 7 | r.current = 1;
|
||||
| ^ Cannot mutate ref during render
|
||||
| ^ Cannot update ref during render
|
||||
8 | }
|
||||
9 | }
|
||||
10 |
|
||||
|
||||
Refs may be mutated during render if initialized with `if (ref.current == null)`
|
||||
```
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ Found 1 error:
|
||||
|
||||
Error: Cannot access ref value during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.invalid-ref-value-as-props.ts:4:19
|
||||
2 | function Component(props) {
|
||||
|
||||
@@ -19,7 +19,7 @@ Found 1 error:
|
||||
|
||||
Error: Cannot access ref value during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.invalid-set-and-read-ref-during-render.ts:5:9
|
||||
3 | const ref = useRef(null);
|
||||
|
||||
@@ -19,7 +19,7 @@ Found 1 error:
|
||||
|
||||
Error: Cannot access ref value during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.invalid-set-and-read-ref-nested-property-during-render.ts:5:9
|
||||
3 | const ref = useRef({inner: null});
|
||||
|
||||
@@ -19,20 +19,18 @@ function useHook({value}) {
|
||||
```
|
||||
Found 1 error:
|
||||
|
||||
Error: Mutating refs during render is not allowed
|
||||
Error: Cannot access refs during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.invalid-write-but-dont-read-ref-in-render.ts:5:2
|
||||
3 | const ref = useRef(null);
|
||||
4 | // Writing to a ref in render is against the rules:
|
||||
> 5 | ref.current = value;
|
||||
| ^^^ Cannot mutate ref during render
|
||||
| ^^^ Cannot update ref during render
|
||||
6 | // returning a ref is allowed, so this alone doesn't trigger an error:
|
||||
7 | return ref;
|
||||
8 | }
|
||||
|
||||
Refs may be mutated during render if initialized with `if (ref.current == null)`
|
||||
```
|
||||
|
||||
|
||||
@@ -17,20 +17,18 @@ function Component(props) {
|
||||
```
|
||||
Found 1 error:
|
||||
|
||||
Error: Mutating refs during render is not allowed
|
||||
Error: Cannot access refs during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.invalid-write-ref-prop-in-render.ts:4:2
|
||||
2 | function Component(props) {
|
||||
3 | const ref = props.ref;
|
||||
> 4 | ref.current = true;
|
||||
| ^^^ Cannot mutate ref during render
|
||||
| ^^^ Cannot update ref during render
|
||||
5 | return <div>{value}</div>;
|
||||
6 | }
|
||||
7 |
|
||||
|
||||
Refs may be mutated during render if initialized with `if (ref.current == null)`
|
||||
```
|
||||
|
||||
|
||||
@@ -27,19 +27,17 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
```
|
||||
Found 1 error:
|
||||
|
||||
Error: Mutating refs during render is not allowed
|
||||
Error: Cannot access refs during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
7 | const r = useRef(DEFAULT_VALUE);
|
||||
8 | if (r.current == DEFAULT_VALUE) {
|
||||
> 9 | r.current = 1;
|
||||
| ^ Cannot mutate ref during render
|
||||
| ^ Cannot update ref during render
|
||||
10 | }
|
||||
11 | }
|
||||
12 |
|
||||
|
||||
Refs may be mutated during render if initialized with `if (ref.current == null)`
|
||||
```
|
||||
|
||||
|
||||
@@ -26,19 +26,17 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
```
|
||||
Found 1 error:
|
||||
|
||||
Error: Mutating refs during render is not allowed
|
||||
Error: Cannot access refs during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
6 | const guard = r.current == null;
|
||||
7 | if (guard) {
|
||||
> 8 | r.current = 1;
|
||||
| ^ Cannot mutate ref during render
|
||||
| ^ Cannot update ref during render
|
||||
9 | }
|
||||
10 | }
|
||||
11 |
|
||||
|
||||
Refs may be mutated during render if initialized with `if (ref.current == null)`
|
||||
```
|
||||
|
||||
|
||||
@@ -26,19 +26,17 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
```
|
||||
Found 1 error:
|
||||
|
||||
Error: Mutating refs during render is not allowed
|
||||
Error: Cannot access refs during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
6 | const r2 = useRef(null);
|
||||
7 | if (r.current == null) {
|
||||
> 8 | r2.current = 1;
|
||||
| ^^ Cannot mutate ref during render
|
||||
| ^^ Cannot update ref during render
|
||||
9 | }
|
||||
10 | }
|
||||
11 |
|
||||
|
||||
Refs may be mutated during render if initialized with `if (ref.current == null)`
|
||||
```
|
||||
|
||||
|
||||
@@ -26,19 +26,17 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
```
|
||||
Found 1 error:
|
||||
|
||||
Error: Mutating refs during render is not allowed
|
||||
Error: Cannot access refs during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
7 | r.current = 1;
|
||||
8 | }
|
||||
> 9 | r.current = 1;
|
||||
| ^ Cannot mutate ref during render
|
||||
| ^ Cannot update ref during render
|
||||
10 | }
|
||||
11 |
|
||||
12 | export const FIXTURE_ENTRYPOINT = {
|
||||
|
||||
Refs may be mutated during render if initialized with `if (ref.current == null)`
|
||||
```
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ Found 1 error:
|
||||
|
||||
Error: Cannot access ref value during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.ref-optional.ts:5:9
|
||||
3 | function Component(props) {
|
||||
|
||||
@@ -33,15 +33,15 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
```
|
||||
Found 1 error:
|
||||
|
||||
Error: Mutating refs during render is not allowed
|
||||
Error: Cannot access refs during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.todo-useCallback-set-ref-nested-property-ref-modified-later-preserve-memoization.ts:14:2
|
||||
12 |
|
||||
13 | // The ref is modified later, extending its range and preventing memoization of onChange
|
||||
> 14 | ref.current.inner = null;
|
||||
| ^^^^^^^^^^^ Cannot mutate ref during render
|
||||
| ^^^^^^^^^^^ Cannot update ref during render
|
||||
15 |
|
||||
16 | return <input onChange={onChange} />;
|
||||
17 | }
|
||||
|
||||
@@ -36,15 +36,15 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
```
|
||||
Found 1 error:
|
||||
|
||||
Error: Mutating refs during render is not allowed
|
||||
Error: Cannot access refs during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.useCallback-accesses-ref-mutated-later-via-function-preserve-memoization.ts:15:4
|
||||
13 | // The ref is modified later, extending its range and preventing memoization of onChange
|
||||
14 | const reset = () => {
|
||||
> 15 | ref.current.inner = null;
|
||||
| ^^^^^^^^^^^ Cannot mutate ref during render
|
||||
| ^^^^^^^^^^^ Cannot update ref during render
|
||||
16 | };
|
||||
17 | reset();
|
||||
18 |
|
||||
|
||||
@@ -32,15 +32,15 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
```
|
||||
Found 1 error:
|
||||
|
||||
Error: Mutating refs during render is not allowed
|
||||
Error: Cannot access refs during render
|
||||
|
||||
React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef.
|
||||
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).
|
||||
|
||||
error.useCallback-set-ref-nested-property-dont-preserve-memoization.ts:13:2
|
||||
11 | });
|
||||
12 |
|
||||
> 13 | ref.current.inner = null;
|
||||
| ^^^^^^^^^^^ Cannot mutate ref during render
|
||||
| ^^^^^^^^^^^ Cannot update ref during render
|
||||
14 |
|
||||
15 | return <input onChange={onChange} />;
|
||||
16 | }
|
||||
|
||||
@@ -47,7 +47,7 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
## Logs
|
||||
|
||||
```
|
||||
{"kind":"CompileError","fnLoc":{"start":{"line":6,"column":0,"index":158},"end":{"line":11,"column":1,"index":331},"filename":"mutate-after-useeffect-ref-access.ts"},"detail":{"options":{"category":"Refs","reason":"Mutating refs during render is not allowed","description":"React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef","details":[{"kind":"error","loc":{"start":{"line":9,"column":2,"index":289},"end":{"line":9,"column":16,"index":303},"filename":"mutate-after-useeffect-ref-access.ts"},"message":"Cannot mutate ref during render"}]}}}
|
||||
{"kind":"CompileError","fnLoc":{"start":{"line":6,"column":0,"index":158},"end":{"line":11,"column":1,"index":331},"filename":"mutate-after-useeffect-ref-access.ts"},"detail":{"options":{"category":"Refs","reason":"Cannot access refs during render","description":"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)","details":[{"kind":"error","loc":{"start":{"line":9,"column":2,"index":289},"end":{"line":9,"column":16,"index":303},"filename":"mutate-after-useeffect-ref-access.ts"},"message":"Cannot update ref during render"}]}}}
|
||||
{"kind":"AutoDepsDecorations","fnLoc":{"start":{"line":8,"column":2,"index":237},"end":{"line":8,"column":50,"index":285},"filename":"mutate-after-useeffect-ref-access.ts"},"decorations":[{"start":{"line":8,"column":24,"index":259},"end":{"line":8,"column":30,"index":265},"filename":"mutate-after-useeffect-ref-access.ts","identifierName":"arrRef"}]}
|
||||
{"kind":"CompileSuccess","fnLoc":{"start":{"line":6,"column":0,"index":158},"end":{"line":11,"column":1,"index":331},"filename":"mutate-after-useeffect-ref-access.ts"},"fnName":"Component","memoSlots":0,"memoBlocks":0,"memoValues":0,"prunedMemoBlocks":0,"prunedMemoValues":0}
|
||||
```
|
||||
|
||||
@@ -47,7 +47,7 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
## Logs
|
||||
|
||||
```
|
||||
{"kind":"CompileError","fnLoc":{"start":{"line":6,"column":0,"index":190},"end":{"line":11,"column":1,"index":363},"filename":"mutate-after-useeffect-ref-access.ts"},"detail":{"options":{"category":"Refs","reason":"Mutating refs during render is not allowed","description":"React refs are mutable containers that should only be mutated outside of render, such as in event handlers or effects. Mutating a ref during render can cause bugs because the mutation may not be associated with a particular render. See https://react.dev/reference/react/useRef","details":[{"kind":"error","loc":{"start":{"line":9,"column":2,"index":321},"end":{"line":9,"column":16,"index":335},"filename":"mutate-after-useeffect-ref-access.ts"},"message":"Cannot mutate ref during render"}]}}}
|
||||
{"kind":"CompileError","fnLoc":{"start":{"line":6,"column":0,"index":190},"end":{"line":11,"column":1,"index":363},"filename":"mutate-after-useeffect-ref-access.ts"},"detail":{"options":{"category":"Refs","reason":"Cannot access refs during render","description":"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)","details":[{"kind":"error","loc":{"start":{"line":9,"column":2,"index":321},"end":{"line":9,"column":16,"index":335},"filename":"mutate-after-useeffect-ref-access.ts"},"message":"Cannot update ref during render"}]}}}
|
||||
{"kind":"AutoDepsDecorations","fnLoc":{"start":{"line":8,"column":2,"index":269},"end":{"line":8,"column":50,"index":317},"filename":"mutate-after-useeffect-ref-access.ts"},"decorations":[{"start":{"line":8,"column":24,"index":291},"end":{"line":8,"column":30,"index":297},"filename":"mutate-after-useeffect-ref-access.ts","identifierName":"arrRef"}]}
|
||||
{"kind":"CompileSuccess","fnLoc":{"start":{"line":6,"column":0,"index":190},"end":{"line":11,"column":1,"index":363},"filename":"mutate-after-useeffect-ref-access.ts"},"fnName":"Component","memoSlots":0,"memoBlocks":0,"memoValues":0,"prunedMemoBlocks":0,"prunedMemoValues":0}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user