Skip to content
Source
Sign inSign up
TanStack/store

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

MergedIdrisCelik(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/364/headmerged 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. Review in 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: 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)
      • packages/svelte-store/tests/ObjectSelector.test.svelte

      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

      useSelector now 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

      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 coverage and release changeset
      packages/svelte-store/tests/ObjectSelector.test.svelte, packages/svelte-store/tests/index.test.ts, .changeset/svelte-selector-identity.md
      The test checks that updating the ignored field 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 747ef

      The selector identity fix and its regression coverage show no outstanding merge-blocking issue.

      Pre-merge checks | Passed 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Title checkPassedThe title clearly identifies the Svelte Store fix and the preserved selector object identity. It is concise and directly matches the main change.
      Description checkPassedThe description includes the required Changes, Checklist, and Release Impact sections. It explains the motivation, documents regression coverage and the changeset, and marks the required checklist ite…
      Linked Issues checkPassedIssue #363 requires identity-preserving selection for the default strict comparator and avoidance of unnecessary invalidation for unchanged object selections. `packages/svelte-store/src/useSelector.sv…
      Out of Scope Changes checkPassedThe reviewed changes are limited to the useSelector initialization, regression coverage for unchanged object selections, and a patch changeset. These changes directly support issue #363 and do not d…
      Docstring CoveragePassedDocstring 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. (1 skipped: 1 …


      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR


      Warning

      Some tools did not complete. Review the errors below.

      🔧 ESLint

      If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

      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
      Comment `@coderabbitai help` to get the list of available commands.
    2. View your CI Pipeline Execution ↗ for commit 747efe31eac39bac144cdc45a272faa4ae3c5cb8

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded26sView ↗
      nx run-many --target=build --exclude=examples/**✅ Succeeded2sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-10-09 22:50:03 UTC

    3. 🦋 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
      NameType
      @tanstack/svelte-storePatch

      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

    4. @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@364

      commit: 747efe3

Sign in to join this conversation.