Docs: is a store proxy read inside an open setter guaranteed to return the staged value?

オープン 初心者向け
#5,200 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
1/5
見積もり時間
1〜3時間
初心者へのやさしさ
88/100
issue の種類
ドキュメント
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, typescript
領域
documentation

調査の方向性

documentation/solid-2.0/04-stores.mdを読み、特に「Draft-first store setters」を確認し、issueで言及されている保留中のbackingに関するstore internalsの注記も確認してください。setterが開いている間のproxy読み取りが意図された動作かを確かめ、その保証をガイドおよび/またはcreateStoreのTSDocに記述してください。ドキュメントに、setter内でstore.xが何を読み取るのかが明記され、確定済みの値との違いが曖昧でなくなれば完了です。

索引モデルが issue の本文から書いたものです。

説明

What this is

A documentation request about an existing 2.0 store behaviour, with a script that shows it. We hit it porting a Solid 1 app (kolu) to Solid 2.

Inside an open setter, a read through the store proxy (store.x, not draft.x) returns the value the setter has staged so far, not the last committed one. That is very useful — a helper called from inside the setter only has the store, not the draft — but we could not find it stated anywhere in the docs, so we do not know whether we may rely on it.

Version

[email protected] (latest) and [email protected] (next), Node 24, Linux. Same output on both.

Reproduction
// staged-read.js
import { createRoot, createStore, flush } from "solid-js";

let store, setStore;
createRoot(() => {
  [store, setStore] = createStore({ seen: 0, rows: ["a"] });
});

// a helper that only has the store, not the draft
const seenSoFar = () => store.seen;

console.log("outside a setter:      store.seen =", store.seen);

setStore((draft) => {
  draft.seen = 1;
  draft.rows.push("b");
  console.log("inside the setter:     store.seen =", store.seen);
  console.log("inside the setter:     store.rows =", JSON.stringify(store.rows));
  console.log("inside the setter:     draft.seen =", draft.seen);
  console.log("inside the setter, via a helper that reads the store:", seenSoFar());
});
flush();
console.log("after the setter:      store.seen =", store.seen);

// folding frames: every line reads what the lines before it staged
setStore((draft) => {
  for (const n of [2, 3, 4]) {
    draft.seen = store.seen + 1;
    if (store.seen !== n) throw new Error(`expected ${n}, read ${store.seen}`);
  }
});
flush();
console.log("after folding 3 frames: store.seen =", store.seen);
$ npm i [email protected]
$ node --conditions=browser --conditions=development staged-read.js
outside a setter:      store.seen = 0
inside the setter:     store.seen = 1
inside the setter:     store.rows = ["a","b"]
inside the setter:     draft.seen = 1
inside the setter, via a helper that reads the store: 1
after the setter:      store.seen = 1
after folding 3 frames: store.seen = 4
The ask

Either:

  • document it — one or two sentences under "Draft-first store setters" in documentation/solid-2.0/04-stores.md (and/or in createStore's TSDoc), saying that while a setter is open the proxy serves the setter's staged view, so store.x inside the callback reads what earlier lines of that callback wrote; or
  • say it is not a guarantee, in which case we will thread the draft through every helper instead.

Today the only statement we could find is in the store internals (the proxy serving the "pending backing" the draft mutates), which reads as an implementation note rather than a promise to users. 04-stores.md covers the draft-first setter, returning a value for a shallow replace, path-setter migration, class instances and snapshot, but says nothing about reading the store itself while a setter is open.

Why it matters to us

Code that folds incremental frames does the update in one setter and calls small helpers from inside it; those helpers close over the store, not the draft. If the staged view is a guarantee, that shape is correct and pleasant. If it is incidental, every such helper needs the draft threaded in, and we would rather change that now than after it silently starts reading committed values.


This was written by an AI agent (Claude) under a human maintainer's direction.

主要言語
TypeScript
スター
37k
フォーク
1.2k
平均マージ
8時間 43分
マージ済み PR(30日)
365

環境構築

はじめの一歩

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

solidjs/solid のほかの issue

solidjs/solid の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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