Skip to content

[2.0 / next] createOptimisticStore(fn) swallows the error when fn reads a failed async memo (createStore delivers it) #4437

Closed

Description

@ryansolid

A derived createOptimisticStore(fn, [], { key }) whose fn reads an async createMemo never reports that memo's rejection: readers keep the last value, with no error and no pending. The same fn under createStore delivers the error, and so does createOptimisticStore when fn awaits the promise itself.

Found at next 5e68925 (2.0.0-rc.20): a ReactiveScript app's list, after a failed reload, stayed on its old rows (or its Loading fallback) instead of showing the Errored fallback.

Repro (packages/signals/tests)

import { it } from "vitest";
import { createEffect, createMemo, createOptimisticStore, createStore, createRoot, createSignal, 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 ["optimistic", "store"]) for (const form of ["await", "memo-async", "memo-sync"])
it(`${kind} over a failing loader, ${form}`, async () => {
  const asks: { key: string; res: (v: any) => void; rej: (e: any) => void }[] = [];
  const ask = (key: string) => new Promise<any>((res, rej) => asks.push({ key, res, rej }));
  const settle = async (key: string, f: (a: any) => void) => { for (const a of asks.filter(a => a.key === key)) { asks.splice(asks.indexOf(a), 1); f(a); } await tick(); };
  const frames: string[] = []; let setFilter!: (f: string) => void;
  createRoot(() => {
    const [filter, sf] = createSignal("open"); setFilter = sf;
    const m = createMemo(() => ask(`f:${filter()}`));
    const make: any = kind === "store" ? createStore : createOptimisticStore;
    const write = (d: any[], r: any) => { d.length = 0; d.push(...r.map((x: any) => ({ ...x }))); };
    const [issues] = make(form === "memo-sync" ? (d: any[]) => { write(d, m()); }
      : async (d: any[]) => { write(d, form === "memo-async" ? m() : await ask(`f:${filter()}`)); }, [], { key: "id" });
    createEffect(() => (issues as any[]).map(i => `#${i.id}`).join(" "),
      { effect: (v: string) => { frames.push(v); }, error: (e: any) => { frames.push(`ERR ${e?.message ?? e}`); } } as any);
  });
  await tick();
  await settle("f:open", a => a.res([{ id: 1 }, { id: 3 }]));
  setFilter("closed"); flush(); await tick();
  await settle("f:closed", a => a.rej(new Error("timeout")));
  console.log(`${kind} ${form}: ` + frames.join(" | "));
});

Output

optimistic await:      #1 #3 | ERR timeout
optimistic memo-async: #1 #3                 <- error lost
optimistic memo-sync:  #1 #3                 <- error lost
store await:           #1 #3 | ERR timeout
store memo-async:      #1 #3 | ERR timeout
store memo-sync:       #1 #3 | ERR timeout

Expected

ERR timeout in all six. Reading a failed memo inside the optimistic store's derive should error the store, as it does for createStore.

Related, both closed: #4271 (a keyed createProjection over a memo swallows later errors) and #4364.

Activity

  1. ryansolid commented on Oct 30, 2026

    @ryansolid
    MemberAuthor

    Fixed on next by #4457 (5315127); 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