Skip to content

fix: track nested deep optimistic store pending state#2748

Merged
ryansolid merged 2 commits into
solidjs:nextfrom
brenelz:fix-nested-deep-optimistic-pending
Jun 7, 2026
Merged

fix: track nested deep optimistic store pending state#2748
ryansolid merged 2 commits into
solidjs:nextfrom
brenelz:fix-nested-deep-optimistic-pending

Conversation

@brenelz
Copy link
Copy Markdown
Contributor

@brenelz brenelz commented Jun 7, 2026

Fixes #2718

Fix: Nested deep(optimisticStore) Pending State

Problem

isPending(() => deep(optimisticStore)) stayed false during an optimistic transition when the optimistic write happened inside a nested object or array.

Example:

setStore(s => {
  s.items[0].name = "Modified";
});

In this case, the optimistic value was visible immediately, but isPending(() => deep(store)) did not become true until a later refresh().

Root Cause

deep() uses snapshotImpl() to recursively traverse a store and subscribe to every nested store node.

When snapshotImpl() found a store proxy, it reset the proxy lookup map to the global store lookup:

lookup = storeLookup;

That works for regular stores, but optimistic stores use their own STORE_LOOKUP map for nested proxies.

Because the traversal switched back to the global lookup, nested optimistic objects could be traversed as plain data instead of through their optimistic store proxies. As a result, isPending() did not collect the nested pending source.

Fix

Preserve the current store's lookup map when one exists:

lookup = target[STORE_LOOKUP] ?? storeLookup;

This keeps nested traversal inside the optimistic store's proxy graph, allowing deep() to read the nested optimistic nodes and allowing isPending() to observe their pending state immediately.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 7, 2026

🦋 Changeset detected

Latest commit: e17633c

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

This PR includes changesets to release 9 packages
Name Type
@solidjs/signals Patch
test-integration Patch
solid-js Patch
babel-preset-solid Patch
@solidjs/web Patch
@solidjs/html Patch
@solidjs/h Patch
@solidjs/universal Patch
@solidjs/element 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

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jun 7, 2026

Merging this PR will not alter performance

✅ 118 untouched benchmarks


Comparing brenelz:fix-nested-deep-optimistic-pending (e17633c) with next (f083220)

Open in CodSpeed

Co-authored-by: Cursor <cursoragent@cursor.com>
@ryansolid ryansolid merged commit 03369dd into solidjs:next Jun 7, 2026
1 of 2 checks passed
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 participants