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

未关闭 适合新手
#5,200 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1-3 小时
新手友好度
88/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
活跃
领域
documentation

调研方向

阅读 documentation/solid-2.0/04-stores.md,尤其是“Draft-first store setters”,并查看关于 issue 中所提 pending 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 分钟
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 摘要。