Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Chiusa
#4,437 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, typescript
Ambito
frontend

Direzione di ricerca

Start with the createOptimisticStore implementation and the related createStore error handling, then add the supplied reproduction under packages/signals/tests. Compare the await, memo-async, and memo-sync cases to see where the rejection is lost. Done means all six cases report ERR timeout, matching the expected output.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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 5e68925c (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.

Lingua principale
TypeScript
Stelle
36.2k
Fork
1.1k
Merge medio
11h 48m
PR unite (30g)
441

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di solidjs/solid

Tutte le issue di solidjs/solid

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.