[signals] A guess that mounts a row reading a failed createOptimistic re-asks it, and the guess waits for that re-ask

Đang mở
#5,195 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@itisrmk đang làm issue này rồi.

Từ ngày 28/11/2026.

  • #5260 của @itisrmk — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
22/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, typescript
Lĩnh vực
frontend

Hướng nghiên cứu

The reproduction is a vitest test that uses render, For, Errored, Loading, createOptimistic and createSignal(async) from solid. Start by running that test and reading how an optimistic layer over a failed async signal re-runs its source when a new row mounts. The fix needs the reactive core, so done means the guess shows at once while b is still failed, and the test's asks list holds only move:2.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

On main (signals unchanged since 30e7805eb), take two lists, each a createSignal(async) with a createOptimistic(() => truth()) layer over it. List b has failed. Each row of list a reads a memo over b inside its own Errored. Then a guess on a that gives a row a new object makes For mount a new row. That row's read of the memo re-runs b's async function: a second request goes out, though nothing asked for it. The guess then stays off screen until that request answers. If the request fails again, the guess shows.

When b is a plain createSignal(async) with no optimistic layer, the same test passes: there is no re-ask and the guess shows at once.

We found this through a board app. A move guess didn't show while another column had failed, and a detail pane beside it tore: its id was the new selection, its title the old one.

/**
 * @jsxImportSource @solidjs/web
 * @vitest-environment jsdom
 */
import { test, expect } from "vitest";
import { For, Loading, Errored, action, createMemo, createSignal, createOptimistic, flush } from "solid-js";
import { render } from "../src/index.js";
const tick = async () => { for (let i = 0; i < 4; i++) { await new Promise(r => setTimeout(r, 0)); flush(); } };
type C = { id: number };

test("a guess that mounts a row reading a failed optimistic signal re-asks it and is held on that re-ask", async () => {
  const asks: any[] = [];
  const ask = (k: string) => new Promise<any>((res, rej) => asks.push({ k, res, rej }));
  const find = (k: string) => asks.splice(asks.findIndex(a => a.k === k), 1)[0];
  const [aT] = createSignal<C[]>(async () => await ask("a"));
  const [a, guessA] = createOptimistic(() => aT());
  const [bT] = createSignal<C[]>(async () => await ask("b"));
  const [b] = createOptimistic(() => bT());       // b has a guess layer too; no guess is ever made on it
  const full = createMemo(() => b().length >= 3);
  const toFront = action(function* (id: number) {
    guessA(rs => [{ id }, ...rs.filter(x => x.id != id)]);   // a new object for the row, so For mounts a new row
    yield ask(`move:${id}`);
  });
  const c = document.body.appendChild(document.createElement("div"));
  render(() => <Loading fallback="L">
    <For each={a()}>{r => <i>{r.id}<Errored fallback="-"><b>{full() ? "full" : "ok"}</b></Errored></i>}</For>|
    <Errored fallback="b failed">{b().length}</Errored>
  </Loading>, c);
  await tick();
  find("a").res([{ id: 1 }, { id: 2 }]); await tick();
  find("b").rej(new Error("declined")); await tick();
  expect(c.textContent).toBe("1-2-|b failed");
  toFront(2); await tick();
  expect(asks.map(x => x.k)).toEqual(["move:2"]);  // actual: ["move:2", "b"]: the new row's read of `full` re-asks b
  expect(c.textContent).toBe("2-1-|b failed");     // actual: "1-2-|b failed": the guess waits for that re-ask
  // once the re-ask fails again, the guess shows: "2-1-|b failed"
});

Replace const [b] = createOptimistic(() => bT()) with const b = bT and the test passes.

Ngôn ngữ chính
TypeScript
Star
37k
Fork
1.2k
Merge trung bình
8 giờ 43 phút
Pull request đã merge (30 ngày)
365

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của solidjs/solid

Tất cả issue của solidjs/solid

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.