Summary of Changes#
In Svelte 5, using $state(selector(source.get())) wraps any selected objects or arrays in deeply reactive proxies. This causes several issues when using useSelector:
- Comparing
compare(slice, data) compares the reactive proxy in slice with the raw object from data. Under default reference comparison (===), a Proxy never strictly equals the raw target object, causing false positives and triggering unnecessary updates on unaffected objects.
- Svelte 5 triggers
state_proxy_equality_mismatch warnings / errors in development when checking proxy vs raw object equality.
- Callers reading
storeVal.current receive a proxy rather than the raw object reference, defeating reference equality checks across component boundaries.
This change switches useSelector's internal state holder to let slice = $state.raw(selector(source.get())). Because the selector state holder is updated via reassignment (slice = data), $state.raw retains full reactive signaling when values change while preserving reference identity and avoiding unwanted proxy wrapping.
Validation#
- Added a unit test in
packages/svelte-store ensuring object reference identity is preserved and unchanged object selections do not trigger spurious re-renders.
- Verified all vitest tests and svelte-check type checks pass.
Summary by CodeRabbit#
- Bug Fixes
- Fixed object selection in
@tanstack/svelte-store to preserve original object references and avoid unnecessary re-renders when unrelated store values change.
- Updates to nested selected values continue to trigger re-renders.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
c6dafc75-d41d-46a3-942e-8bb510176492📥 Commits
Reviewing files that changed from the base of the PR and between c1a40d47e2c5e8a1ca30225771870bad8aacc0c2 and 48ca363f2d8186df4b6c8086f790dd5aec6ef053.
📒 Files selected for processing (4)
.changeset/svelte-store-raw-state.mdpackages/svelte-store/src/useSelector.svelte.tspackages/svelte-store/tests/ObjectRender.test.sveltepackages/svelte-store/tests/index.test.tsIncluded 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 with$state.raw. Tests check that the selected object retains its original reference, unrelated updates do not trigger a re-render, and nested updates do.Changes#
Selector state
packages/svelte-store/src/useSelector.svelte.ts,.changeset/svelte-store-raw-state.mduseSelectorinitializesslicewith$state.rawinstead of$state. A patch changeset records the change.packages/svelte-store/tests/ObjectRender.test.svelte,packages/svelte-store/tests/index.test.tsPriority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related PRs
useSelectorstate with$state.rawand cover raw object identity.Merge Risk: ⚪ Minimal · up to
48ca3The selector change has no identified issue requiring a fix before merge.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
## 🎯 Changes,## ✅ Checklist, or## 🚀 Release Impactsections, and it does not record th…pnpm test:prchecklist items. Confirm the release impact by selecting the published-code option and noting the generated changeset, or select the docs/CI/dev-only option …✅ Passed checks (4 passed)
useSelectorto prevent proxy equality mismatches.Full details: Description check
Explanation
The description explains the motivation, implementation, and validation. It does not include the required
## 🎯 Changes,## ✅ Checklist, or## 🚀 Release Impactsections, and it does not record the checklist status or changeset impact.Resolution
Add the required template sections. Mark the contributing-guide and
pnpm test:prchecklist items. Confirm the release impact by selecting the published-code option and noting the generated changeset, or select the docs/CI/dev-only option if applicable.✨ Finishing Touches
🧪 Generate unit tests (beta)
Warning
Some tools did not complete. Review the errors below.
🔧 ESLint
packages/svelte-store/src/useSelector.svelte.ts
ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.
packages/svelte-store/tests/ObjectRender.test.svelte
ESLint skipped: the matched ESLint configuration already failed (missing-dependency).
packages/svelte-store/tests/index.test.ts
ESLint skipped: the matched ESLint configuration already failed (missing-dependency).
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