[2.0 / next] A rejection under an armed <Loading on> reveals a stale value and commits a write held outside it

Chiusa
#4,591 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à
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
18/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, typescript
Ambito
frontend

Direzione di ricerca

Start with the reproduction spec in packages/web/test/, which uses render, createMemo, and <Loading on={...}> inside <Errored>, and run it with npx vitest run. The fifth frame is the one to explain: it shows a0 beside s1=2 while the write is held. Trace how Loading and Errored decide which frame to show when a memo rejects during a held transition. Done means the spec passes and the expected frames hold, which probably requires a maintainer decision on the intended semantics first.

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

Descrizione

Describe the bug

a0 and a1 both ask by s1. a1 is read outside a <Loading on={s0()}>, and a0 and s1 are read inside it. A handler writes s0 and s1 together, so the boundary re-arms and the s1 write is held on a1, which is read outside.

When a0's new question rejects while a1's is still out, the boundary drops its fallback and shows a0=10, the answer for s1 = 0, beside s1=2. Next to it, a1 still shows 11, its answer for s1 = 1. So one frame shows three different values of s1. The frame becomes error only when a1:2 lands.

Found by checking every frame of generated ryansolid/reactivescript programs, compiled onto Solid, against F-1.

Your Example Website or App

The vitest spec below (in packages/web/test/), on next @ 77be406ca.

Steps to Reproduce the Bug or Issue
import { render } from "@solidjs/web";
import { createMemo, createSignal, Errored, flush, Loading } from "solid-js";
import { expect, it } from "vitest";

const tick = async () => { for (let i = 0; i < 2; i++) { await new Promise(r => setTimeout(r, 0)); flush(); } };

it("a rejection under an armed <Loading on> does not reveal a stale value or commit a held write", async () => {
  const flights = new Map<string, { resolve: (v: number) => void; reject: (e: Error) => void }>();
  const ask = (key: string) => new Promise<number>((resolve, reject) => flights.set(key, { resolve, reject }));
  const [s0, setS0] = createSignal(0);
  const [s1, setS1] = createSignal(0);
  const el = document.createElement("div");
  const frames: string[] = [];
  const dispose = render(() => {
    const a0 = createMemo(() => ask("a0:" + s1()));
    const a1 = createMemo(() => ask("a1:" + s1()));
    return (
      <Errored fallback={<p>error</p>}>
        <p>[a1={a1()}]</p>
        <Loading on={s0()} fallback={<p>loading</p>}>
          <p>[a0={a0()}]</p>
          <p>[s1={s1()}]</p>
        </Loading>
      </Errored>
    );
  }, el);
  await tick();
  flights.get("a1:0")!.resolve(9); flights.get("a0:0")!.resolve(10); await tick(); frames.push(el.textContent!);
  setS0(1); setS1(1); flush(); await tick();       frames.push(el.textContent!);
  flights.get("a1:1")!.resolve(11); await tick();  frames.push(el.textContent!);
  setS0(2); setS1(2); flush(); await tick();       frames.push(el.textContent!);
  flights.get("a0:2")!.reject(new Error("boom")); await tick(); frames.push(el.textContent!);
  flights.get("a1:2")!.resolve(12); await tick();  frames.push(el.textContent!);
  dispose();
  expect(frames).toEqual([
    "[a1=9][a0=10][s1=0]",
    "[a1=9][a0=10][s1=0]",
    "[a1=11]loading",
    "[a1=11]loading",
    "[a1=11]loading",   // received "[a1=11][a0=10][s1=2]"
    "error",
  ]);
});

npx vitest run in packages/web. The fifth frame is [a1=11][a0=10][s1=2]. The same happens when the outside reader is wrapped in <Show when={s1() > 0}>.

Expected behavior

While the s1 = 2 write is held, the boundary keeps its fallback and s1 is not committed (F-2, F-5). The rejection is an answer for s1 = 2, and it shows when a value for that question would (F-12, D-41). In no frame does a0 show its answer for s1 = 0 beside s1=2.

Platform
  • OS: macOS
  • Browser: n/a (jsdom)
  • Version: solid-js 2.0.0-rc.20, next @ 77be406ca
Lingua principale
TypeScript
Stelle
36.2k
Fork
1.1k
Merge medio
10h 10m
PR unite (30g)
505

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.