Skip to content

fix(signals): merge an action's refresh() hold with an existing guess's hold (#5344) - #5349

Open
MindOfqc wants to merge 1 commit into
solidjs:mainfrom
MindOfqc:fix/signals-refresh-hold-after-guess-5344
Open

MindOfqc wants to merge 1 commit into
solidjs:mainfrom
MindOfqc:fix/signals-refresh-hold-after-guess-5344

Conversation

@MindOfqc

@MindOfqc MindOfqc commented Dec 6, 2026

Copy link
Copy Markdown

Summary

Fixes #5344.

Problem

When action A places an optimistic guess on an async or sync createOptimistic signal o before action B calls refresh(o) (guess-first), ending A allows the refresh's landed value to commit immediately while B is still open. In refresh-first order, the screen keeps the guess until B ends (matching RULES-DERIVED.md D-31 & D-33). In addition, yield refresh(o) inside B hung waiting on A's hold while A remained open.

Root Cause

  1. In refresh-first, B's refresh(o) parked o in txB (CONFIG_HELD), so A's subsequent applyGuesses() saw CONFIG_HELD, created the guess lane under txB, and merged txA and txB.
  2. In guess-first, o was already in A's guess lane (CONFIG_OVERRIDE | CONFIG_GUESS) under txA. When B called refresh(o):
    • notifyStatus() (packages/signals/src/core/async.ts) ran joinFuture(null) on REACTIVE_REASK, which was a no-op when flushTransaction was already txB (and otherwise opened a spurious transaction on bare outside-action refresh(o)).
    • GlobalQueue.settle() (packages/signals/src/core/scheduler.ts) skipped all CONFIG_OVERRIDE nodes in pendingNodes, leaving txB completely disconnected from o and txA. When A ended, supersede() staged the landed refresh value into txA, whose _open count had reached 0, committing immediately while B was still open.
  3. For synchronous createOptimistic recomputations, laneOutcome() (packages/signals/src/core/guesses.ts) superseded into txA without merging the active flushTransaction.

Fix

  • packages/signals/src/core/async.ts: on CONFIG_GUESS entering STATUS_PENDING, skip joinFuture when REACTIVE_REASK is set so bare outside refresh(o) does not open a spurious transaction, leaving hold merging to settle().
  • packages/signals/src/core/scheduler.ts: in GlobalQueue.settle(), when parking into a real hold t, merge txOf(n)._parent with t for any CONFIG_GUESS node in pendingNodes (gated on guessing so non-optimistic bundles tree-shake it away).
  • packages/signals/src/core/guesses.ts: in laneOutcome(), call joinFuture(txOf(el)._parent) when flushTransaction !== null so synchronous createOptimistic refreshes inside a hold merge with the guess's hold.
  • Updated packages/signals/docs/RULES-INDEX.md citations for D-31 / D-33 and added .changeset/action-refresh-hold-after-guess-5344.md.

How did you test this change?

  • Added 15 regression tests in packages/signals/tests/action-refresh-hold-after-guess-5344.test.ts covering both guess-first and refresh-first orders across:
    • A ends before refresh resolves while B is open (exact [2.0 / main] An action's refresh() answer shows before the action ends when another action's guess came first (D-31) #5344 repro)
    • refresh resolves while both A and B are open, then A ends while B is open
    • yield refresh(o) inside B delivering the staged value while screen keeps the guess (D-31)
    • downstream derived memo remaining on guess while B is open
    • synchronous createOptimistic refresh inside B staying held after A ends
    • bare outside-action refresh(o) control (no spurious hold on sibling sync writes)
    • 3-action chained refresh (A -> B -> C) and same-tick non-action hold
  • Test validity check (before vs after fix):
    • With only src/core/{async,guesses,scheduler}.ts reverted to upstream/main: pnpm --filter @solidjs/signals exec vitest run tests/action-refresh-hold-after-guess-5344.test.ts -> 7 failed | 8 passed (15) (all 7 guess-first / chained / non-action hold cases reproduce the leak).
    • With the fix applied: 15 passed (15).
  • Full verification:
    • pnpm --filter @solidjs/signals build (rollup + mangle-props + check-pure + tsc -p tsconfig.build.json) -> passed, 0 errors/warnings in changed files.
    • pnpm --filter @solidjs/signals exec vitest run tests/action-refresh-hold-after-guess-5344.test.ts -> 15 passed (15).
    • Existing optimistic / refresh / action / guess / spec test suites (123 functional test files in packages/signals) -> 1,924 passed, 0 failed; full packages/signals (577 non-Windows-path-harness files) and packages/solid (59 non-Windows-harness files, 945 tests) passed.
    • pnpm --filter ./packages/solid test-types -> passed.
    • node scripts/rules-index.mjs --check (LF + POSIX path verified) -> every src/ citation resolves (110 ids); docs/RULES-INDEX.md is current.
    • pnpm exec prettier --check on all authored/edited code & changeset files -> passed.
    • node scripts/check-release-invariants.mjs -> passed.

…'s hold (solidjs#5344)

Problem:
When an action B calls 
efresh(o) on a createOptimistic value that already
carries another action A's guess, the refresh answer showed immediately as soon
as it landed after A ended — while B was still open — violating D-31 ("Called
inside a hold, the landing is staged into that hold") and D-33 ("A change that
would alter what a guess sits on merges with that guess's hold..."). When the
refresh started before the guess, �pplyGuesses() merged the two holds and kept
the guess on screen until B ended.

Root cause:
- In packages/signals/src/core/async.ts (
otifyStatus), a guessed node going
  pending on REACTIVE_REASK called joinFuture(null) instead of joining the
  guess's parent transaction, leaving action B's transaction unmerged with A's.
- In packages/signals/src/core/scheduler.ts (GlobalQueue.settle), the
  pendingNodes loop skipped nodes with CONFIG_OVERRIDE (including
  CONFIG_GUESS), so o was never associated with B's transaction 	, leaving
  	._nodes empty and disconnected from A's lane parent. When A ended and the
  refresh landed, supersede() staged the answer into A's transaction, which
  was no longer blocked (_open === 0) and committed immediately while B was
  still open.
- For synchronous createOptimistic recomputes, laneOutcome() in
  packages/signals/src/core/guesses.ts superseded directly into A's parent
  without merging with lushTransaction.

Fix:
- packages/signals/src/core/async.ts: on a CONFIG_GUESS node going pending,
  do not open a spurious transaction for REACTIVE_REASK (if (passLane ===
  null && !(el._flags & REACTIVE_REASK)) joinFuture(txOf(el)._parent)).
- packages/signals/src/core/scheduler.ts: in GlobalQueue.settle(), when
  parking into a hold 	 (	 !== null), merge 	xOf(n)._parent! into 	 for
  any CONFIG_GUESS node queued in pendingNodes (gated on guessing so
  non-optimistic bundles fold it away).
- packages/signals/src/core/guesses.ts: in laneOutcome(), join
  	xOf(el)._parent when lushTransaction !== null so synchronous refreshes
  inside a hold merge symmetrically.
- Added regression tests in
  packages/signals/tests/action-refresh-hold-after-guess-5344.test.ts, updated
  packages/signals/docs/RULES-INDEX.md, and added a patch changeset.

Verification:
- Mutation proof: reverting the 3 source files caused 7/15 tests in
  �ction-refresh-hold-after-guess-5344.test.ts to fail; restoring passed 15/15.
- @solidjs/signals build + 	sc -p tsconfig.build.json + test suite
  (577 functional test files passed; only 3 pre-existing Windows-only harness
  files failed on ENAMETOOLONG / CRLF / path separators; Linux-equivalent
  
ules-index.mjs --check passed).
- packages/solid build + types + test-types + tests (59/61 passed; 2
  pre-existing Windows-only harness files).
- prettier --check and
ode scripts/check-release-invariants.mjs passed.
@changeset-bot

changeset-bot Bot commented Dec 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6dce579

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@solidjs/signals Patch
@solidjs/web Patch
@solidjs/diagnostics Patch
solid-js Patch
@solidjs/universal Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[2.0 / main] An action's refresh() answer shows before the action ends when another action's guess came first (D-31)

1 participant