[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 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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
平均マージ
11時間 5分
マージ済み PR(30日)
475

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

solidjs/solid のほかの issue

solidjs/solid の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。