fix(svelte-store): preserve selector object identity #364
main fromrefs/pull/364/head·merged by crutchcorn(GitHub profile, opens in a new tab) 🎯 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
- Object selections now preserve their identity when the selected value hasn’t changed, preventing updates to unrelated store state from triggering unnecessary re-renders.
- Tests
- Added coverage to verify that unchanged object selections remain stable when other store state is updated.
- 1
View your CI Pipeline Execution ↗ for commit 747efe31eac39bac144cdc45a272faa4ae3c5cb8
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 26s View ↗ nx run-many --target=build --exclude=examples/**✅ Succeeded 2s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-09 22:50:03UTC🦋 Changeset detected#
Latest commit: 747efe31eac39bac144cdc45a272faa4ae3c5cb8
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
Name Type @tanstack/svelte-store 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
@tanstack/angular-store
npm i https://pkg.pr.new/@tanstack/angular-store@364@tanstack/lit-store
npm i https://pkg.pr.new/@tanstack/lit-store@364@tanstack/octane-store
npm i https://pkg.pr.new/@tanstack/octane-store@364@tanstack/preact-store
npm i https://pkg.pr.new/@tanstack/preact-store@364@tanstack/react-store
npm i https://pkg.pr.new/@tanstack/react-store@364@tanstack/solid-store
npm i https://pkg.pr.new/@tanstack/solid-store@364@tanstack/store
npm i https://pkg.pr.new/@tanstack/store@364@tanstack/svelte-store
npm i https://pkg.pr.new/@tanstack/svelte-store@364@tanstack/vue-store
npm i https://pkg.pr.new/@tanstack/vue-store@364commit:
747efe3crutchcorn(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
a90d2fbf-e900-4df9-9ef1-f1f1e16e0fe6📥 Commits
Reviewing files that changed from the base of the PR and between b1e9b7739a96e7dfb415e77f02162bf7b1fdb626 and 747efe31eac39bac144cdc45a272faa4ae3c5cb8.
📒 Files selected for processing (1)
packages/svelte-store/tests/ObjectSelector.test.svelte🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
📝 Walkthrough
Walkthrough#
useSelectornow initializes its selected value as raw state. A regression test checks that updating an unselected field does not increase the render count. A changeset declares a patch release for@tanstack/svelte-store.Changes#
Svelte selector identity
packages/svelte-store/src/useSelector.svelte.ts$state.raw(...)instead of$state(...).packages/svelte-store/tests/ObjectSelector.test.svelte,packages/svelte-store/tests/index.test.ts,.changeset/svelte-selector-identity.md@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
747efThe selector identity fix and its regression coverage show no outstanding merge-blocking issue.
Pre-merge checks |
5
✅ Passed checks (5 passed)
#363requires identity-preserving selection for the default strict comparator and avoidance of unnecessary invalidation for unchanged object selections. `packages/svelte-store/src/useSelector.sv…useSelectorinitialization, regression coverage for unchanged object selections, and a patch changeset. These changes directly support issue#363and do not d…✨ Finishing Touches
🧪 Generate unit tests (beta)
Warning
Some tools did not complete. Review the errors below.
🔧 ESLint
packages/svelte-store/tests/ObjectSelector.test.svelte
ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.
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