Repository navigation
fix(store): replace reactive Set/Map state on hydration instead of unioning it - #3162
Merged
Merged
Conversation
…ioning it When a setup store's state contains a reactive(new Set()) / reactive(new Map()) with default entries, hydrating from server state unioned the two collections instead of replacing them, so defaults the server had removed survived. The sibling ref() branch and HMR both replace, and the server state is authoritative. Clear the reactive Set/Map before merging in the hydration path only, leaving $patch's own merge semantics unchanged. The existing hydration tests used empty defaults, so they never exercised this.
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughSetup-store hydration now clears reactive ChangesReactive collection hydration
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
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.
Fixes #3161.
Problem
When a setup store's state has a
reactive(new Set([...]))/reactive(new Map([...]))with default entries, SSR hydration unions the defaults with the server state instead of replacing them, so entries the server removed survive (repro in #3161). The siblingref()branch and HMR both replace; the server state is authoritative.Cause
The reactive-hydration branch calls
mergeReactiveObjects, whose Set/Map branches add server entries onto the client collection without clearing it first.Fix
Clear a reactive
Set/Mapbefore merging in the hydration path only (store.ts), leaving$patch's own merge semantics (which also callsmergeReactiveObjects) unchanged.Tests
Added a hydration test with non-empty reactive Set/Map defaults asserting the server state replaces them (the existing tests used empty defaults, so union == replace and the bug was invisible). It fails before this change and passes after; the full pinia suite stays green (211 passed), including
$patch, and typecheck is clean.Summary by CodeRabbit
SetandMapvalues in setup stores.Set/Mapcontents now fully replace existing default entries, preventing stale items from lingering after hydration.Set/Maphydration behavior for both top-level and nested reactive structures.