[2.0 rc.20 / next] `deep()`/`snapshot()` return the pre-action store when an action that wrote before and after a `yield` lands

已关闭
#4,552 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

Start with the repro test in packages/signals/tests/ that imports action, deep, snapshot and createStore from ../src/index.js. Compare the held-landing visibility check used by deep()/snapshot() with the per-key read path, and see how the earlier fix in aa03f76e (#3147) shares that decision. Done when deep(state) and snapshot(state) match the store after an action with writes before and after a yield lands.

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

描述

Describe the bug

When an action writes a store before and after a yield, the computations that re-run when it lands see its writes through per-key reads (state.a), but deep(state) and snapshot(state) in the same run return the store as it was before the action. They miss the write made before the yield as well.

Nothing re-runs afterwards, so the stale value sticks:

  • An effect over deep(state), like the persistence example in the stores RFC (createEffect(() => deep(store), snapshot => saveToLocalStorage(JSON.stringify(snapshot)))), receives the pre-action state and doesn't run again.
  • createMemo(() => deep(state)) keeps returning { a: 0, b: 0 } after everything has settled, while the store holds { a: 1, b: 1 } and snapshot(state) read outside any computation returns { a: 1, b: 1 }.

This looks related to #3147, fixed in aa03f76e by having deep()/snapshot() and per-key readers share one held-landing visibility decision. That issue was the reverse case: deep() ran ahead of per-key reads while a transaction held a landing. Here the action has landed and per-key reads show it, but deep()/snapshot() still answer as if it were held.

Your Example Website or App

Inline below: a vitest test for packages/signals/tests/ that uses only the package's own exports.

Steps to Reproduce the Bug or Issue

Drop this into packages/signals/tests/ and run it:

import { expect, it } from "vitest";
import { action, createEffect, createRoot, createStore, deep, flush, snapshot } from "../src/index.js";

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

it("deep()/snapshot() see an action's writes when it lands", async () => {
  const [state, setState] = createStore({ a: 0, b: 0 });
  const seen: any[] = [];
  createRoot(() =>
    createEffect(
      () => ({ deep: deep(state), snap: snapshot(state), a: state.a, b: state.b }),
      v => void seen.push(v)
    )
  );
  await settle();

  let release!: () => void;
  const gate = new Promise<void>(r => (release = r));
  action(function* () {
    setState(d => { d.a = 1; });
    yield gate;
    setState(d => { d.b = 1; });
  })();
  await settle();
  release();
  await settle();

  expect(seen.at(-1)).toEqual({ deep: { a: 1, b: 1 }, snap: { a: 1, b: 1 }, a: 1, b: 1 });
  // actual: { deep: { a: 0, b: 0 }, snap: { a: 0, b: 0 }, a: 1, b: 1 }
});

What changes the outcome (deep(state) in the run after the action lands, same setup):

Case Result
The same writes without action (generator stepped by hand) ✅ { a: 1, b: 1 }
Action with a write before the yield only ✅ { a: 1, b: 0 }
Action with writes before and after the yield ❌ { a: 0, b: 0 }
createMemo(() => deep(state)), read after settling ❌ { a: 0, b: 0 }; the store is { a: 1, b: 1 }

The effect does re-run exactly once when the action lands, so the notification arrives; it's the values deep()/snapshot() read in that run that are stale.

Expected behavior

In the run where the action lands, deep(state) and snapshot(state) match per-key reads: { a: 1, b: 1 }. A memo over deep(state) ends up equal to the store.

Platform
  • next @ 50dec1b3a (2026-10-31), in the signals package's own vitest setup
  • @solidjs/signals 2.0.0-rc.20 from npm, both the dev (dist/dev.js) and prod (dist/prod/index.js) builds
  • @solidjs/signals 2.0.0-rc.19 (dev build)
  • Node 24.18.0, macOS 26.5.2
Additional context

Found while recording deep(store) from an effect after each commit.

主要语言
TypeScript
星标
36.2k
派生
1.1k
平均合并
10 小时 10 分钟
30 天内合并 PR
505

环境准备

从这里开始

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

solidjs/solid 的其他 Issue

查看 solidjs/solid 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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