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

Fermée
#4,591 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
18/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
javascript, typescript
Domaine
frontend

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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
Langage dominant
TypeScript
Étoiles
36.2k
Forks
1.1k
Merge moyen
10 h 39 min
PR mergées (30 j)
500

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de solidjs/solid

Toutes les issues de solidjs/solid

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.