mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
[compiler] Fix to ref access check to ban ref?.current
ghstack-source-id: ea417a468e
Pull Request resolved: https://github.com/facebook/react/pull/31360
This commit is contained in:
parent
cae764ce81
commit
fe04dbcbc4
|
|
@ -214,16 +214,24 @@ function joinRefAccessTypes(...types: Array<RefAccessType>): RefAccessType {
|
||||||
return b;
|
return b;
|
||||||
} else if (b.kind === 'None') {
|
} else if (b.kind === 'None') {
|
||||||
return a;
|
return a;
|
||||||
} else if (a.kind === 'Guard' || b.kind === 'Guard') {
|
} else if (a.kind === 'Guard') {
|
||||||
if (a.kind === 'Guard' && b.kind === 'Guard' && a.refId === b.refId) {
|
if (b.kind === 'Guard' && a.refId === b.refId) {
|
||||||
return a;
|
return a;
|
||||||
|
} else if (b.kind === 'Nullable' || b.kind === 'Guard') {
|
||||||
|
return {kind: 'None'};
|
||||||
|
} else {
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
return {kind: 'None'};
|
} else if (b.kind === 'Guard') {
|
||||||
} else if (a.kind === 'Nullable' || b.kind === 'Nullable') {
|
if (a.kind === 'Nullable') {
|
||||||
if (a.kind === 'Nullable' && b.kind === 'Nullable') {
|
return {kind: 'None'};
|
||||||
return a;
|
} else {
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
return {kind: 'None'};
|
} else if (a.kind === 'Nullable') {
|
||||||
|
return b;
|
||||||
|
} else if (b.kind === 'Nullable') {
|
||||||
|
return a;
|
||||||
} else {
|
} else {
|
||||||
return joinRefAccessRefTypes(a, b);
|
return joinRefAccessRefTypes(a, b);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
|
||||||
|
## Input
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import {useRef} from 'react';
|
||||||
|
|
||||||
|
function Component(props) {
|
||||||
|
const ref = useRef();
|
||||||
|
return ref?.current;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
|
fn: Component,
|
||||||
|
params: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Error
|
||||||
|
|
||||||
|
```
|
||||||
|
3 | function Component(props) {
|
||||||
|
4 | const ref = useRef();
|
||||||
|
> 5 | return ref?.current;
|
||||||
|
| ^^^^^^^^^^^^ InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (5:5)
|
||||||
|
6 | }
|
||||||
|
7 |
|
||||||
|
8 | export const FIXTURE_ENTRYPOINT = {
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
import {useRef} from 'react';
|
||||||
|
|
||||||
|
function Component(props) {
|
||||||
|
const ref = useRef();
|
||||||
|
return ref?.current;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
|
fn: Component,
|
||||||
|
params: [],
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user