Skip to content

fix(svelte-store): preserve selector object identity - #364

Open
IdrisCelik wants to merge 1 commit into
TanStack:mainfrom
IdrisCelik:main
Open

IdrisCelik wants to merge 1 commit into
TanStack:mainfrom
IdrisCelik:main

Conversation

@IdrisCelik

@IdrisCelik IdrisCelik commented Sep 13, 2026

Copy link
Copy Markdown

🎯 Changes

Updated the Svelte adapter's useSelector to initialize selected state with $state.raw(...) instead of $state(...).

This preserves raw object identity for the default strict equality comparator, preventing state_proxy_equality_mismatch warnings and unnecessary invalidations when object-valued selections have not changed.

Added regression coverage for unchanged object selections and added a patch Changeset.

Fixes #363

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes

    • Fixed object selections in useSelector so unchanged selected values preserve their identity.
    • Updates to unrelated store state no longer trigger unnecessary re-renders for object selections.
  • Tests

    • Added coverage verifying selector isolation and stable render behavior.
  • Chores

    • Documented the patch release for the Svelte store package.

@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: ed1e0b16-dfa3-432a-8e30-930699f991d6

📥 Commits

Reviewing files that changed from the base of the PR and between 3b060e3 and b1e9b77.

📒 Files selected for processing (4)
  • .changeset/svelte-selector-identity.md
  • packages/svelte-store/src/useSelector.svelte.ts
  • packages/svelte-store/tests/ObjectSelector.test.svelte
  • packages/svelte-store/tests/index.test.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

useSelector now stores its initial selected value as raw state. New Svelte tests verify that updates outside the selected object do not trigger an additional render. A patch changeset records the fix.

Changes

Svelte selector identity

Layer / File(s) Summary
Raw selector state
packages/svelte-store/src/useSelector.svelte.ts
The initial selector result uses $state.raw(...) instead of $state(...).
Regression test and release metadata
packages/svelte-store/tests/ObjectSelector.test.svelte, packages/svelte-store/tests/index.test.ts, .changeset/svelte-selector-identity.md
The tests verify that updating the ignored state does not increase the render count. The changeset declares a patch release for @tanstack/svelte-store.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to b1e9b

The selector now preserves object identity for unchanged selections, and the added regression test covers ignored state updates. The change is ready to merge.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (2 skipped: 2 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving object identity for Svelte store selectors.
Description check ✅ Passed The description covers the change, motivation, regression tests, changeset, issue reference, checklist, and release impact. All required template sections are present and complete.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

useSelector wraps selected objects in $state, causing state_proxy_equality_mismatch and defeating identity comparison

1 participant