[2.0.4] A `latest()` binding keeps showing an optimistic guess after its action ends, when a refresh landed a different value during the action
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Start with verdictRead in packages/signals/src/core/verdict.ts and trace how held latest() readers are notified when a hold commits. Reproduce the signal and store cases from the issue, including key: null, and check the existing tests for verdict and optimistic values. Done means render effects reading latest() update to the server value after the action ends; an open linked pull request already addresses this issue.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
An action writes an optimistic guess and waits. While it waits, a refresh() from outside the action (a poll, another component) lands a different server value beneath the guess. As documented, the screen and latest() keep the guess until the action ends. When the action ends without refreshing again, the screen switches to the server value and an imperative latest() call returns it, but a render effect (a JSX binding) that reads latest() never re-runs. It keeps showing the guess indefinitely, until something else makes it re-run.
This happens with a createOptimistic value as well as with a field of a createOptimisticStore row (keyed or key: null).
Reproduction
This runs against @solidjs/signals directly (the same primitives solid-js exports). Each render effect stands in for a JSX binding: {label()}, {latest(label)}, {isPending(label)}.
import {
action, createOptimistic, createOptimisticStore, createRenderEffect, createRoot,
flush, isPending, latest, refresh
} from "@solidjs/signals";
const tick = async () => {
for (let i = 0; i < 4; i++) {
flush();
await new Promise(r => setTimeout(r, 0));
}
};
async function run(form) {
let server = "B";
const seen = {};
const h = createRoot(() => {
const [label, setLabel] = createOptimistic(async () => {
await Promise.resolve();
return server;
});
const [rows, setRows] = createOptimisticStore(async () => {
await Promise.resolve();
return [{ id: "b", label: server }];
}, [], { key: "id" });
const read = form === "signal" ? label : () => rows[0]?.label;
createRenderEffect(read, v => void (seen.screen = v));
createRenderEffect(() => latest(read), v => void (seen.latest = v));
createRenderEffect(() => isPending(read), v => void (seen.pending = v));
return {
read,
source: form === "signal" ? label : rows,
guess: v => (form === "signal" ? setLabel(v) : setRows(d => void (d[0].label = v)))
};
});
const frame = step =>
console.log(form.padEnd(6), step.padEnd(8), JSON.stringify({ ...seen, "latest()": latest(h.read) }));
await tick();
frame("initial");
let finish;
const save = action(function* () {
h.guess("Guess");
yield new Promise(r => (finish = r));
})();
await tick();
frame("guess");
server = "Server B"; // the server changed the row meanwhile
refresh(h.source); // e.g. a poll, outside the action
await tick();
frame("refresh");
finish(); // the action ends without refreshing
await save;
await tick();
frame("end");
}
await run("signal");
await run("store");
Expected
After the action ends, every reader shows the server value. The latest() binding agrees with the screen and with an imperative latest() call:
signal end {"latest":"Server B","pending":false,"screen":"Server B","latest()":"Server B"}
store end {"latest":"Server B","pending":false,"screen":"Server B","latest()":"Server B"}
Actual
The latest() binding stays on the guess, while the screen, isPending and an imperative latest() have all moved on:
signal initial {"latest":"B","pending":false,"screen":"B","latest()":"B"}
signal guess {"latest":"Guess","pending":false,"screen":"Guess","latest()":"Guess"}
signal refresh {"latest":"Guess","pending":false,"screen":"Guess","latest()":"Guess"}
signal end {"latest":"Guess","pending":false,"screen":"Server B","latest()":"Server B"}
store initial {"latest":"B","pending":false,"screen":"B","latest()":"B"}
store guess {"latest":"Guess","pending":false,"screen":"Guess","latest()":"Guess"}
store refresh {"latest":"Guess","pending":true,"screen":"Guess","latest()":"Guess"}
store end {"latest":"Guess","pending":false,"screen":"Server B","latest()":"Server B"}
The guess and refresh rows are as documented (D-34: "the screen, untracked reads and latest of the displayed slot keep the guess until the commit"). Only the end row is wrong. A store with key: null gives the same output. When the action itself calls refresh() before it ends, the end row is correct: the answer landing then re-runs the binding.
Versions
@solidjs/signals2.0.4: reproduces (output above).- main at
34485971a: reproduces (the same output, signal and store, keyed andkey: null). - also 2.0.3.
Cause
A latest() reader of a held guess is linked to the node and routed to its hold, but not queued to re-run when the hold commits. verdictRead in packages/signals/src/core/verdict.ts (line 173 on main) queues only isPending probes:
/** A verdict read of a held node. A probe re-runs at the landing because
* nothing notifies its flip; `latest` needs no re-run, the landing reaches
* it through its link. */
function verdictRead(c: Computed<any>, t: Transaction, plain?: boolean): void {
route(c, t);
if (plain) staleReader(c, t);
else if (probing && t._reruns[t._reruns.length - 1] !== c) t._reruns.push(c);
}
The comment's assumption is that latest changes when an answer lands, and the landing notifies it through its link. Since latest keeps a corrected guess until the commit (D-34, the keptGuess(el) && blocked(t) arm near line 521), the refresh's landing no longer changes what latest returns. The change from the guess to the server value happens at the commit, and nothing notifies the latest() reader then. The screen's bindings are re-derived at the commit as the hold's readers, which is why they update.
In a local experiment, queuing latest readers as probes are queued ((probing || latestActive) && … in that line) makes all three forms show Server B at the end. I haven't run the full test suite on that change.
- Ngôn ngữ chính
- TypeScript
- Star
- 37k
- Fork
- 1.2k
- Merge trung bình
- 8 giờ 43 phút
- Pull request đã merge (30 ngày)
- 365
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của solidjs/solid
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[2.0.4] Nested `<Errored>`: the outer boundary stays on an error the inner one rethrew, after the next error is one the inner one handlesCó thể đã có người làm @MilindChatrabhuji đã nhận 2 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của solidjs/solid
Issue tương tự
-
agentscan:mixed-signals pending triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
vueuse/vueuse#5737 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 9 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Marker-Inc-Korea/AutoRAG#2288 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Resources: New templates of Guangzhou Metro Line 13Có thể đã có người làm @rmt-svc đã nhận hôm nay. Đang mởresources
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 76/100
railmapgen/rmg-templates#2730 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
web
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày