Skip to content

[2.0 / next] A keyed createProjection stops updating after its fn returned an async store's proxy, then a plain array #4361

Closed

Description

@ryansolid

Found by: the ReactiveScript AI eval. An agent wrote shownIssues key id = filter == "open" ? issues.filter(…) : issues. .rx lowers that to a memo over the expression plus createProjection(() => memo(), [], { key: "id" }), so the projection returns the memo's value: sometimes the store proxy, sometimes a plain array.

On: next @ ac28157 (2.0.0-rc.19 + #4330).

Program

  • issues is a keyed createStore (or createOptimisticStore) derived from an async fn that reads filter().
  • A memo returns issues.filter(…) (a plain array) when filter() === "open", and the issues proxy itself otherwise.
  • createProjection(() => memo(), [], { key: "id" }) is read by a render effect.

Steps

  1. Land open.
  2. Switch to closed and land closed.
  3. Switch back to open and land open, with a changed row.

Frames

  • Expected: #1(-) #3(-) → #2(eve) → #1(-) #3(ann)
  • Actual: #1(-) #3(-) → #2(eve), and it stays there.

The projection updates correctly in each of these cases:

  • the memo always returns a plain array ([...issues]);
  • the projection reads the store directly, without the memo;
  • the source is synchronous.

Test (packages/signals/tests)

Prints the frames for each of the four combinations. The two memo=true lines stop at #2(eve).

import { it } from "vitest";
import { createMemo, createOptimisticStore, createProjection, createRenderEffect, createRoot, createSignal, createStore, flush } from "../src/index.js";
const tick = async () => { for (let i = 0; i < 4; i++) { await new Promise(r => setTimeout(r, 0)); flush(); } };
for (const kind of ["optimisticStore", "store"]) for (const memo of [true, false])
it(`${kind} memo=${memo}`, async () => {
  const asks: { key: string; res: (v: any) => void }[] = [];
  const ask = (key: string) => new Promise<any>(res => asks.push({ key, res }));
  const land = async (key: string, v: any) => { const i = asks.findIndex(a => a.key === key); asks.splice(i, 1)[0].res(v); await tick(); };
  const frames: string[] = []; let setFilter!: (f: string) => void;
  createRoot(() => {
    const [filter, sf] = createSignal("open"); setFilter = sf;
    const make: any = kind === "store" ? createStore : createOptimisticStore;
    const [issues] = make(async (d: any[]) => { const r = await ask(`f:${filter()}`); d.length = 0; d.push(...r.map((x: any) => ({ ...x }))); }, [], { key: "id" });
    const src = memo ? createMemo(() => filter() === "open" ? (issues as any[]).filter(() => true) : issues) : () => issues;
    const p = createProjection(() => src() as any, [] as any, { key: "id" } as any);
    createRenderEffect(() => (p as any).map((i: any) => `#${i.id}(${i.a})`).join(" "), v => { if (frames.at(-1) !== v) frames.push(v); });
  });
  await land("f:open", [{ id: 1, a: "-" }, { id: 3, a: "-" }]);
  setFilter("closed"); flush(); await tick(); await land("f:closed", [{ id: 2, a: "eve" }]);
  setFilter("open"); flush(); await tick(); await land("f:open", [{ id: 1, a: "-" }, { id: 3, a: "ann" }]);
  console.log(`${kind} memo=${memo}: ` + frames.join(" | "));
});

Activity

  1. ryansolid commented on Oct 28, 2026

    @ryansolid
    MemberAuthor

    Fixed on next by #4368 (5f60713); it ships in the next RC.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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