fix(react-db): idiomatic useLiveQuery & useLiveSuspenseQuery hooks - #1721
fix(react-db): idiomatic useLiveQuery & useLiveSuspenseQuery hooks#1721zeorin wants to merge 1 commit into
useLiveQuery & useLiveSuspenseQuery hooks#1721Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesReact live-query hooks
Estimated code review effort: 3 (Moderate) | ~20 minutes Mergeability Score: ⚪ Minimal · up to The PR replaces ref-based version tracking with state in two published React hooks and includes a changeset. No actionable merge-blocking risk remains; it is merge-ready after normal checks and review. Possibly related PRs
🚥 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 |
a9de250 to
5f23973
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/react-db/src/useLiveQuery.ts`:
- Around line 335-340: The needsNewCollection condition should not use
!collection as its initialization check, because disabled queries may
intentionally leave collection null and repeatedly update state. In the relevant
useLiveQuery logic, use prevDeps === null for initialization while preserving
the existing config and dependency-change checks.
In `@packages/react-db/src/useLiveSuspenseQuery.ts`:
- Around line 190-193: Guard the ready-state update in the useLiveSuspenseQuery
flow by calling setHasBeenReady(true) only when collectionStatus is ready and
hasBeenReady is false, preventing repeated render-phase state updates while
preserving the existing ready-state behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 8779cc43-0926-4a80-a890-cde7642f1fab
📒 Files selected for processing (3)
.changeset/eleven-gifts-shine.mdpackages/react-db/src/useLiveQuery.tspackages/react-db/src/useLiveSuspenseQuery.ts
5f23973 to
5582d36
Compare
These hooks where using refs to track previous versions of certain variables, and reading those during render, which is an anti-pattern that breaks the Rules of Hooks and may lead to subtle bugs, especially in concurrent mode. Using state instead is more idiomatic and ensures there will be no state tearing, even during concurrent mode updates.
5582d36 to
66ed096
Compare
🎯 Changes
These hooks where using refs to track previous versions of certain variables, and reading those during render, which is an anti-pattern that breaks the Rules of Hooks and may lead to subtle bugs, especially in concurrent mode.
Using state instead is more idiomatic and ensures there will be no state tearing, even during concurrent mode updates.
I discovered this while trying to work around an issue where an error thrown by the
queryFninQueryCollectionwould lead to infinite retries, and eventually, the browser running out of memory.TODO: I haven't yet checked or adjusted the following hooks:
useLiveInfiniteQueryuseLiveQueryEffectusePacedMutations✅ Checklist
pnpm test. There are failing tests, but they were not introduced by my changes.🚀 Release Impact
Summary by CodeRabbit