mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[rhir] Patch for reactive computed loads
We need to check reactivity of both the operand and its resolved source (if operand is produced by a LoadLocal / PropertyLoad / ComputedLoad). Both the operand and its source can have reactivity. e.g. ```js const o = makeObject(); // source has no reactivity const x = o[props.x]; // x is reactive ```
This commit is contained in:
@@ -45,9 +45,19 @@ class Visitor extends ReactiveFunctionVisitor<State> {
|
||||
if (operand.effect === Effect.Store) {
|
||||
continue;
|
||||
}
|
||||
const resolvedId: IdentifierId =
|
||||
state.temporaries.get(operand.identifier.id) ?? operand.identifier.id;
|
||||
if (state.reactivityMap.get(resolvedId)) {
|
||||
const ownId = operand.identifier.id;
|
||||
const resolvedId = state.temporaries.get(ownId);
|
||||
// We need to check reactivity of both the operand and its resolved source (if operand is
|
||||
// produced by a LoadLocal / PropertyLoad / ComputedLoad). Both the operand and its source
|
||||
// can have reactivity. e.g.
|
||||
// ```js
|
||||
// const o = makeObject(); // source has no reactivity
|
||||
// const x = o[props.x]; // x is reactive
|
||||
// ```
|
||||
if (
|
||||
state.reactivityMap.get(ownId) ||
|
||||
(resolvedId && state.reactivityMap.get(resolvedId))
|
||||
) {
|
||||
hasReactiveInput = true;
|
||||
break;
|
||||
}
|
||||
|
||||
+10
-6
@@ -18,16 +18,20 @@ function Component(props) {
|
||||
|
||||
```javascript
|
||||
function Component(props) {
|
||||
const $ = React.unstable_useMemoCache(1);
|
||||
const $ = React.unstable_useMemoCache(2);
|
||||
const a = foo();
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t0 = bar(a[props.a] + 1);
|
||||
|
||||
const t0 = a[props.a] + 1;
|
||||
const c_0 = $[0] !== t0;
|
||||
let t1;
|
||||
if (c_0) {
|
||||
t1 = bar(t0);
|
||||
$[0] = t0;
|
||||
$[1] = t1;
|
||||
} else {
|
||||
t0 = $[0];
|
||||
t1 = $[1];
|
||||
}
|
||||
const b = t0;
|
||||
const b = t1;
|
||||
return b;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user