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:
Joe Savona
2023-12-14 12:05:25 -08:00
parent 873a286029
commit fc36043019
2 changed files with 72 additions and 0 deletions
@@ -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>
@@ -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 }],
};