[2.0.4] `isPending()` stays `false` while an input change's request is out under an optimistic guess

未关闭
#5,255 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@yumemi-thomas 已经在做这个了。

开始于 2026年11月28日。

  • #5256 来自 @yumemi-thomas —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
领域
frontend

调研方向

Read core/async.ts, especially notifyStatus, joinFuture, and propagateStatus, to understand why the guess branch does not notify readers. Reproduce with the linked Solid Playground and inspect packages/web/test/async-gen/rulings/S-44.ts; the existing it.fails test is the likely place to update. Confirm that tracked isPending(comments) becomes true during the held request and false after the refresh, while the held screen and optimistic guess remain correct.

由索引模型根据 Issue 内容生成。

描述

comments is an optimistic async value over a signal sel. An action guesses comments and then waits. Changing sel while the action is out is held with the action, so the screen keeps the old sel beside the guess. But isPending(comments) stays false while the request for the new sel is out, and turns true only once that request has answered.

Reproduction

Playground link (2.0.4)

import { createSignal, createOptimistic, action, refresh, isPending, latest, Loading } from "solid-js";

const wait = (ms: number) => new Promise<void>(r => setTimeout(r, ms));
// Answers after 1s: 3 → 4, 1 → 2.
const fetchComments = async (sel: number) => (await wait(1000), sel + 1);

export default function App() {
  const [sel, setSel] = createSignal(3);
  const [comments, setComments] = createOptimistic(() => fetchComments(sel()));
  const post = action(function* () {
    setComments(9); // the guess
    yield wait(4000); // the post request
    refresh(comments);
  });

  return (
    <Loading>
      <button onClick={() => post()}>1. post</button>
      <button onClick={() => setSel(1)}>2. select 1</button>
      <p>
        sel {sel()} | comments {comments()} | latest {latest(comments)} | isPending{" "}
        {String(isPending(comments))}
      </p>
    </Loading>
  );
}

Steps

  1. Wait for sel 3 | comments 4 | latest 4 | isPending false.
  2. Click 1. post.
  3. Within a second, click 2. select 1. Watch the line for the next ~5 seconds.

Expected

isPending true from step 3 until the post's refresh lands: changing sel asks a new question, and that change "is held with the post" (S-44; F-9, D-23: pending while a new question has no committed answer).

Actual

screen
after step 2 sel 3 | comments 9 | latest 9 | isPending false
step 3, select 1 request out (1s) sel 3 | comments 9 | latest 9 | isPending false
select 1 answered, post still out sel 3 | comments 9 | latest 9 | isPending true
post done, refresh lands sel 1 | comments 2 | latest 2 | isPending false

So a disabled={isPending(comments)} or a "refreshing…" indicator stays off for exactly as long as the new request is out. The held screen itself is right. It needs the guess: without setComments(9), isPending is true while the select 1 request is out. An untracked isPending(comments) called right after step 3 also returns true; only the tracked read misses it. Same in 2.0.4 and main (510bb8d01), dev and prod.

Cause

When the input change makes comments re-ask while a guess is on it, notifyStatus (core/async.ts) takes the guess branch: it joins the action's hold (joinFuture) and returns before propagateStatus. So the readers of comments, including the isPending probe, are never notified. The probe re-runs only when the answer lands.

Related

Follow-up to #4336 (fixed in #4337, which built the held screen). The pending frame is S-44's setSel(1) row, pinned in the repo as ruled-not-built (packages/web/test/async-gen/rulings/S-44.ts, an it.fails test).

主要语言
TypeScript
星标
37k
派生
1.2k
平均合并
8 小时 43 分钟
30 天内合并 PR
365

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

solidjs/solid 的其他 Issue

查看 solidjs/solid 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。