[2.0.4] A memo over an optimistic list cannot both agree with the shown rows through `latest()` and restart its request when an outside refresh lands

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃

调研方向

Start with the repro using createOptimisticStore, createMemo, latest(), and refresh(), then read packages/signals/docs/RULES-DERIVED.md for D-34 and D-22. Compare keyed and key: null behavior against the changes attempted in #5238. Done means the intended memo semantics are decided and the keyed and null-key cases have a consistent implementation and regression tests.

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

描述

An action removes a row from a createOptimisticStore list and waits. An outside refresh() lands different rows. The list keeps showing the guess until the action ends. A memo over the list then behaves differently by key form, and each form misses one thing:

latest(createMemo(() => items.length)) in the window An async memo that reads items.length to choose its request
keyed the shown length asks again when the action ends, so its answer arrives after the commit frame could have had it
key: null the refetched length (4 beside two shown rows) asks again when the refresh lands

Repro (@solidjs/signals, same with solid-js):

import { createRoot, createOptimisticStore, createMemo, createRenderEffect, action, refresh, flush, latest } from "@solidjs/signals";

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

for (const key of ["id", null]) {
  let server = ["a", "b", "c"];
  const asked = [];
  let shown, latestLen;
  const app = createRoot(() => {
    const [rows, set] = createOptimisticStore(async () => server.map(id => ({ id })), [], { key });
    const len = createMemo(() => rows.length);
    const query = createMemo(async () => { asked.push(rows.length); return rows.length; }); // stands in for a request
    createRenderEffect(() => [rows.length, query()], () => {});
    createRenderEffect(() => latest(len), v => { latestLen = v; });
    createRenderEffect(() => rows.length, v => { shown = v; });
    return { rows, set };
  });
  await settle();
  action(function* () { app.set(d => void d.shift()); yield new Promise(() => {}); })(); // the action never ends here
  await settle();
  server = ["a", "b", "c", "d"]; refresh(app.rows); await settle();
  console.log(`key ${key}: asked ${asked.join(",")} | shown ${shown} | latest(memo) ${latestLen}`);
}

Output, the same on 2.0.4 and main (510bb8d01):

key id: asked 3,2,2 | shown 2 | latest(memo) 2
key null: asked 3,2,4 | shown 2 | latest(memo) 4

With the keyed list the request isn't asked again for the refetched rows until the action ends; with key: null it is, but latest(memo) then reads the refetched length beside the two shown rows.

Cause: a keyed list folds the truth beneath the guess and lane work keeps reading the guess; a key: null list is corrected and its lane's derivations re-derive on the truth. A memo is one node with one version, so it follows one or the other.

D-34 (packages/signals/docs/RULES-DERIVED.md) asks for both: derivations re-derive from the truth now "so downstream refetches restart at once", while the screen and latest of the displayed slot keep the guess. D-22 says a sync derivation of a held value has produced an answer, which reads as latest(memo) being the truth.

Question: which is intended for a memo over a guessed list?

  1. latest(memo) is the truth and the request restarts at once (today's key: null), and keyed lists should move to it; or
  2. latest(memo) agrees with the list, and the request should still restart at once, which needs the folded lane to stage a second derivation for async work.

Folding key: null lists was tried in #5238 and removed: it gave option 2's latest and lost the immediate request.

主要语言
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 摘要。