|
| 1 | + |
| 2 | +## Input |
| 3 | + |
| 4 | +```javascript |
| 5 | +import {useRef} from 'react'; |
| 6 | +import {Stringify} from 'shared-runtime'; |
| 7 | + |
| 8 | +/** |
| 9 | + * Bug: we're currently filtering out `ref.current` dependencies in |
| 10 | + * `propagateScopeDependencies:checkValidDependency`. This is incorrect. |
| 11 | + * Instead, we should always take a dependency on ref values (the outer box) as |
| 12 | + * they may be reactive. Pruning should be done in |
| 13 | + * `pruneNonReactiveDependencies` |
| 14 | + * |
| 15 | + * Found differences in evaluator results |
| 16 | + * Non-forget (expected): |
| 17 | + * (kind: ok) |
| 18 | + * <div>{"cb":{"kind":"Function","result":1},"shouldInvokeFns":true}</div> |
| 19 | + * <div>{"cb":{"kind":"Function","result":2},"shouldInvokeFns":true}</div> |
| 20 | + * Forget: |
| 21 | + * (kind: ok) |
| 22 | + * <div>{"cb":{"kind":"Function","result":1},"shouldInvokeFns":true}</div> |
| 23 | + * <div>{"cb":{"kind":"Function","result":1},"shouldInvokeFns":true}</div> |
| 24 | + */ |
| 25 | +function Component({cond}) { |
| 26 | + const ref1 = useRef(1); |
| 27 | + const ref2 = useRef(2); |
| 28 | + const ref = cond ? ref1 : ref2; |
| 29 | + const cb = () => ref.current; |
| 30 | + return <Stringify cb={cb} shouldInvokeFns={true} />; |
| 31 | +} |
| 32 | + |
| 33 | +export const FIXTURE_ENTRYPOINT = { |
| 34 | + fn: Component, |
| 35 | + params: [{cond: true}], |
| 36 | + sequentialRenders: [{cond: true}, {cond: false}], |
| 37 | +}; |
| 38 | + |
| 39 | +``` |
| 40 | + |
| 41 | +## Code |
| 42 | + |
| 43 | +```javascript |
| 44 | +import { c as _c } from "react/compiler-runtime"; |
| 45 | +import { useRef } from "react"; |
| 46 | +import { Stringify } from "shared-runtime"; |
| 47 | + |
| 48 | +/** |
| 49 | + * Bug: we're currently filtering out `ref.current` dependencies in |
| 50 | + * `propagateScopeDependencies:checkValidDependency`. This is incorrect. |
| 51 | + * Instead, we should always take a dependency on ref values (the outer box) as |
| 52 | + * they may be reactive. Pruning should be done in |
| 53 | + * `pruneNonReactiveDependencies` |
| 54 | + * |
| 55 | + * Found differences in evaluator results |
| 56 | + * Non-forget (expected): |
| 57 | + * (kind: ok) |
| 58 | + * <div>{"cb":{"kind":"Function","result":1},"shouldInvokeFns":true}</div> |
| 59 | + * <div>{"cb":{"kind":"Function","result":2},"shouldInvokeFns":true}</div> |
| 60 | + * Forget: |
| 61 | + * (kind: ok) |
| 62 | + * <div>{"cb":{"kind":"Function","result":1},"shouldInvokeFns":true}</div> |
| 63 | + * <div>{"cb":{"kind":"Function","result":1},"shouldInvokeFns":true}</div> |
| 64 | + */ |
| 65 | +function Component(t0) { |
| 66 | + const $ = _c(1); |
| 67 | + const { cond } = t0; |
| 68 | + const ref1 = useRef(1); |
| 69 | + const ref2 = useRef(2); |
| 70 | + const ref = cond ? ref1 : ref2; |
| 71 | + let t1; |
| 72 | + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { |
| 73 | + const cb = () => ref.current; |
| 74 | + t1 = <Stringify cb={cb} shouldInvokeFns={true} />; |
| 75 | + $[0] = t1; |
| 76 | + } else { |
| 77 | + t1 = $[0]; |
| 78 | + } |
| 79 | + return t1; |
| 80 | +} |
| 81 | + |
| 82 | +export const FIXTURE_ENTRYPOINT = { |
| 83 | + fn: Component, |
| 84 | + params: [{ cond: true }], |
| 85 | + sequentialRenders: [{ cond: true }, { cond: false }], |
| 86 | +}; |
| 87 | + |
| 88 | +``` |
| 89 | + |
0 commit comments