Skip to content

[2.0 / next] A memo that read latest(x) last run holds a Loading on switch even when its new run no longer reads x #4661

Closed

Description

@ryansolid

On next @ 6f33602.

A memo outside a <Loading on={f()}> reads f() and, in the branch taken before the switch, latest(() => list()). When f changes, the new run takes the other branch and does not read list at all. The switch is still held silently until list's new answer lands, so the Loading on fallback never shows and the old content stays on screen. The same memo with untrack in place of latest doesn't hold. A memo that always reads latest(() => list()) doesn't hold either. It holds whether the memo is read by an effect or by a view outside the boundary.

const [f, setF] = createSignal("open");
const list = createMemo(() => ask(`list:${f()}`));            // a promise per key
const count = createMemo(() => f() === "open" ? latest(() => list().length) : -1);
createEffect(() => count(), v => { seen = v; });
return <Loading fallback={<i>first</i>}>
  <Loading on={f()} fallback={<i>loading {f()}</i>}><b>{list().join(",")}</b></Loading>
</Loading>;

Steps: land list:open = [1,2,3], then setF("closed") and flush.

variant after the switch, in flight expected
f() === "open" ? latest(() => list().length) : -1, read by an effect 1,2,3 (held) loading closed
the same, read by a <span> outside the boundary [3]1,2,3 (held) [-1]loading closed
f() === "open" ? untrack(() => list().length) : -1 loading closed ✓
latest(() => list().length) (no branch) loading closed ✓

When list:closed lands, every variant shows 9 and the count -1.

How we found it: ReactiveScript's checker suggests "read latest x here" for a reader outside a loading on(k) region. An app counting open issues, filter == "open" ? (latest shown).length : -1, still froze on the filter switch. Three agents hit it independently and each spent several turns working around it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions