fix(preact-store): recompute selections when selectors change - #367
Merged
Merged
Conversation
Contributor
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
View your CI Pipeline Execution ↗ for commit d9aa136
☁️ Nx Cloud last updated this comment at |
@tanstack/angular-store
@tanstack/lit-store
@tanstack/octane-store
@tanstack/preact-store
@tanstack/react-store
@tanstack/solid-store
@tanstack/store
@tanstack/svelte-store
@tanstack/vue-store
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Changes
Fix a regression introduced by #318 in
@tanstack/preact-store@0.13.1: changing a selector while the store snapshot stays unchanged returns the previous selector's result. For example,useSelector(store, (state) => state[modifier])keeps returning the Alt selection aftermodifierchanges to Control. This surfaced in TanStack Hotkeys while upgrading the adapter.Replace the shared snapshot-cache ref with a selector-local closure created by
useMemo([selector]). A new selector gets a fresh cache, while repeated reads through the same selector still reuse the result for an unchanged snapshot. This preserves the protection against render loops from selectors returning fresh arrays or objects and retains custom equality behavior.Add five test cases covering inline and memoized selectors with changing props, stable-selector caching, equality across selector changes, and fresh array selections across parent rerenders and store updates. Four of the new cases fail on the previous implementation; all pass with the fix, including the existing array-selector regression test from #318.
Validation
CI=1 NX_DAEMON=false pnpm test:prpasses all 17 affected tasks: package tests (55 passing runtime/type test cases), TypeScript 5.6/5.7/5.8/6.0, ESLint, build/publint, workspace checks, and affected Preact example checks/builds.git diff --checkpass.pnpm changeset statusconfirms a patch release for@tanstack/preact-storeonly.✅ Checklist
pnpm test:pr.🚀 Release Impact
Summary by CodeRabbit