mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Fixtures where unmemoized value invalidates later scopes
These fixtures demonstrate how currently, even if the dependency of a scope doesn't get memoized (ie the scope gets pruned), we don't remove later scopes that depend on that value. Those later scopes will always invalidate, so we might as well remove them.
This commit is contained in:
1 parent
22ea72d4e9
commit
48e08c42be
8 files changed
+333
No files matched your search
+63
@@ -0,0 +1,63 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
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];
|
||||
|
||||
return [y];
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "sathya" }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
import { useHook } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(4);
|
||||
const x = [];
|
||||
useHook();
|
||||
x.push(props.value);
|
||||
let t0;
|
||||
if ($[0] !== x) {
|
||||
t0 = [x];
|
||||
$[0] = x;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
const y = t0;
|
||||
let t1;
|
||||
if ($[2] !== y) {
|
||||
t1 = [y];
|
||||
$[2] = y;
|
||||
$[3] = t1;
|
||||
} else {
|
||||
t1 = $[3];
|
||||
}
|
||||
return t1;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "sathya" }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Eval output
|
||||
(kind: ok) [[["sathya"]]]
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
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];
|
||||
|
||||
return [y];
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "sathya" }],
|
||||
};
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
import { useHook } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const o = {};
|
||||
const x = <div>{props.value}</div>; // create within the range of x to group with x
|
||||
useHook(); // intersperse a hook call to prevent memoization of x
|
||||
o.value = props.value;
|
||||
|
||||
const y = <div>{x}</div>;
|
||||
|
||||
return <div>{y}</div>;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "sathya" }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
import { useHook } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(6);
|
||||
const o = {};
|
||||
let t0;
|
||||
if ($[0] !== props.value) {
|
||||
t0 = <div>{props.value}</div>;
|
||||
$[0] = props.value;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
const x = t0;
|
||||
useHook();
|
||||
o.value = props.value;
|
||||
let t1;
|
||||
if ($[2] !== x) {
|
||||
t1 = <div>{x}</div>;
|
||||
$[2] = x;
|
||||
$[3] = t1;
|
||||
} else {
|
||||
t1 = $[3];
|
||||
}
|
||||
const y = t1;
|
||||
let t2;
|
||||
if ($[4] !== y) {
|
||||
t2 = <div>{y}</div>;
|
||||
$[4] = y;
|
||||
$[5] = t2;
|
||||
} else {
|
||||
t2 = $[5];
|
||||
}
|
||||
return t2;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "sathya" }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Eval output
|
||||
(kind: ok) <div><div><div>sathya</div></div></div>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { useHook } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const o = {};
|
||||
const x = <div>{props.value}</div>; // create within the range of x to group with x
|
||||
useHook(); // intersperse a hook call to prevent memoization of x
|
||||
o.value = props.value;
|
||||
|
||||
const y = <div>{x}</div>;
|
||||
|
||||
return <div>{y}</div>;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "sathya" }],
|
||||
};
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
import { useHook } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const x = new Foo();
|
||||
useHook(); // intersperse a hook call to prevent memoization of x
|
||||
x.value = props.value;
|
||||
|
||||
const y = { x };
|
||||
|
||||
return { y };
|
||||
}
|
||||
|
||||
class Foo {}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "sathya" }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
import { useHook } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(4);
|
||||
const x = new Foo();
|
||||
useHook();
|
||||
x.value = props.value;
|
||||
let t0;
|
||||
if ($[0] !== x) {
|
||||
t0 = { x };
|
||||
$[0] = x;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
const y = t0;
|
||||
let t1;
|
||||
if ($[2] !== y) {
|
||||
t1 = { y };
|
||||
$[2] = y;
|
||||
$[3] = t1;
|
||||
} else {
|
||||
t1 = $[3];
|
||||
}
|
||||
return t1;
|
||||
}
|
||||
|
||||
class Foo {}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "sathya" }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Eval output
|
||||
(kind: ok) {"y":{"x":{"value":"sathya"}}}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { useHook } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const x = new Foo();
|
||||
useHook(); // intersperse a hook call to prevent memoization of x
|
||||
x.value = props.value;
|
||||
|
||||
const y = { x };
|
||||
|
||||
return { y };
|
||||
}
|
||||
|
||||
class Foo {}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "sathya" }],
|
||||
};
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
import { useHook } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const x = {};
|
||||
useHook(); // intersperse a hook call to prevent memoization of x
|
||||
x.value = props.value;
|
||||
|
||||
const y = { x };
|
||||
|
||||
return { y };
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "sathya" }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
import { useHook } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(4);
|
||||
const x = {};
|
||||
useHook();
|
||||
x.value = props.value;
|
||||
let t0;
|
||||
if ($[0] !== x) {
|
||||
t0 = { x };
|
||||
$[0] = x;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
const y = t0;
|
||||
let t1;
|
||||
if ($[2] !== y) {
|
||||
t1 = { y };
|
||||
$[2] = y;
|
||||
$[3] = t1;
|
||||
} else {
|
||||
t1 = $[3];
|
||||
}
|
||||
return t1;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "sathya" }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Eval output
|
||||
(kind: ok) {"y":{"x":{"value":"sathya"}}}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { useHook } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const x = {};
|
||||
useHook(); // intersperse a hook call to prevent memoization of x
|
||||
x.value = props.value;
|
||||
|
||||
const y = { x };
|
||||
|
||||
return { y };
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "sathya" }],
|
||||
};
|
||||
Reference in new issue
Block a user