mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fixture for pruning unmemoized nonreactive deps
Adds a fixture for our existing behavior that reactive scope dependencies exclude values which are non-reactive. The idea is that regardless of whether the value may actually get recreated over time or not, a "nonreactive" value cannot semantically change and therefore we can ignore changes in its pointer address.
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
import { mutate, useNoAlias } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
// Here `x` cannot be memoized bc its mutable range spans a hook call:
|
||||
const x = [];
|
||||
useNoAlias();
|
||||
mutate(x);
|
||||
|
||||
// However, `x` is non-reactive. It cannot semantically change, so we
|
||||
// exclude it as a dependency of the JSX element:
|
||||
return <div>{x}</div>;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: 42 }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
import { mutate, useNoAlias } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(1);
|
||||
|
||||
const x = [];
|
||||
useNoAlias();
|
||||
mutate(x);
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t0 = <div>{x}</div>;
|
||||
$[0] = t0;
|
||||
} else {
|
||||
t0 = $[0];
|
||||
}
|
||||
return t0;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: 42 }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Eval output
|
||||
(kind: ok) <div></div>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { mutate, useNoAlias } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
// Here `x` cannot be memoized bc its mutable range spans a hook call:
|
||||
const x = [];
|
||||
useNoAlias();
|
||||
mutate(x);
|
||||
|
||||
// However, `x` is non-reactive. It cannot semantically change, so we
|
||||
// exclude it as a dependency of the JSX element:
|
||||
return <div>{x}</div>;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: 42 }],
|
||||
};
|
||||
Reference in New Issue
Block a user