Fix/live query record drop on subset unmount#1656
Open
jdday wants to merge 1 commit into
Open
Conversation
Contributor
📝 WalkthroughWalkthroughThe PR reorders row tracking and ownership persistence in ChangesQuery Collection Ownership Fix
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
775e89d to
66f109f
Compare
…w updates, as it was previously reading stale owners before any updates causing rows contained within 2 subsets to be removed on unmount
66f109f to
fb9fa21
Compare
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
When a row was first inserted by subset query A,
write({ type: 'insert' })cleared the row's pending metadata.setPersistedOwnerswas called beforewrite, so the ownership it set was immediately overwritten by the insert's metadata-delete.When a later live query called
getHydratedOwnedRowsForQueryBaseline, it read the stale persisted state and overwrote the in-memoryrowToQueriesmap, dropping query A's hash from the owner set. When that query was GC'd, it found zero remaining owners and deleted the row — removing it from unrelated list views.✅ Checklist
pnpm test.🚀 Release Impact
Notes
Currently facing the below issue with react-db and I believe the below re-ordering of lines fixes it for myself but need to understand the impact elsewhere or if there is a better place to add this fix.
Any new live queries seem to take ownership of existing rows when mounting. Meaning that when the new live query unmounts it causes that record to be removed from the collection even if other useLiveQueries still should have that row existing.
I am unsure if this is a similar impact across the other vue/svelte db packages I am currently only using react-db so any advise if this change would negatively impact other areas would be helpful.
One thing noticed - my team have observed that the row will re-appear in the correct live query if we force a re-render during local development
Summary by CodeRabbit
useLiveQuerydoes not remove records from an active broaduseLiveQuery.