mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Fixture for transitive invalidation of effect dep
This fixture shows that this optimization partially improves transitive checking for validateMemoizedEffectDependencies.
This commit is contained in:
1 parent
f4455ef51a
commit
4af3ff1e75
2 files changed
+63
No files matched your search
+44
@@ -0,0 +1,44 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// @validateMemoizedEffectDependencies
|
||||
import { useHook } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const x = [];
|
||||
useHook(); // intersperse a hook call to prevent memoization of x
|
||||
x.push(props.value);
|
||||
|
||||
const y = [x];
|
||||
|
||||
useEffect(() => {
|
||||
console.log(y);
|
||||
}, [y]);
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "sathya" }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
9 | const y = [x];
|
||||
10 |
|
||||
> 11 | useEffect(() => {
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
> 12 | console.log(y);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
> 13 | }, [y]);
|
||||
| ^^^^^^^^^^ [ReactForget] InvalidReact: This effect may trigger an infinite loop: one or more of its dependencies could not be memoized due to a later mutation (11:13)
|
||||
14 | }
|
||||
15 |
|
||||
16 | export const FIXTURE_ENTRYPOINT = {
|
||||
```
|
||||
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// @validateMemoizedEffectDependencies
|
||||
import { useHook } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const x = [];
|
||||
useHook(); // intersperse a hook call to prevent memoization of x
|
||||
x.push(props.value);
|
||||
|
||||
const y = [x];
|
||||
|
||||
useEffect(() => {
|
||||
console.log(y);
|
||||
}, [y]);
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "sathya" }],
|
||||
};
|
||||
Reference in new issue
Block a user