Fixture for transitive invalidation of effect dep

This fixture shows that this optimization partially improves transitive checking 
for validateMemoizedEffectDependencies.
This commit is contained in:
Joe Savona committed 2024-03-06 09:28:03 -08:00
1 parent f4455ef51a
commit 4af3ff1e75
2 files changed
+63

No files matched your search

@@ -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 = {
```
@@ -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" }],
};