fix(react-db): keep paced callbacks tied to committed renders #2170
main fromrefs/pull/2170/head·merged by KyleAMathews Changes#
usePacedMutations previously assigned callback refs during render. When a transition from document A to B suspended, A remained visible but B's callbacks could become active. A save from A could then update or persist B.
Publish onMutate and mutationFn in useInsertionEffect. A committed render refreshes both callbacks before descendant layout effects can call mutate. The returned mutate function keeps its identity across callback changes.
Oracle coverage#
The React render-cut oracle replaces the eight original example tests. Its independent model selects the callback owner from the committed document. It runs five histories with and without StrictMode:
- A mutation before a candidate render suspends.
- A visible mutation after that render suspends.
- A mutation after the candidate commits.
- Delayed persistence from a descendant layout effect.
- Immediate persistence from a descendant layout effect.
The oracle compares ordered callback traces and public Collection rows. It also checks mutate identity after a commit. The original render-time implementation fails four of ten histories. A layout-effect-only mutant fails the descendant histories. A split insertion/layout mutant fails immediate persistence.
Core pacing retains its separate oracle for timing, admission, ordering, and settlement. The React oracle does not decide callback affinity when another render commits between admission and persistence. Issue #2178 tracks shared adapter conformance once another framework has an equivalent hook.
Checklist#
- React package tests pass: 22 files, 412 tests, and no type errors on the original branch base.
- The same package passes 418 tests after integration with current
main. - Core paced-mutations oracle passes 154 tests.
- React package build, focused ESLint, Prettier, and
git diff --checkpass.
Release impact#
- Published
@tanstack/react-dbbehavior changes. This PR includes a patch changeset. - This change is documentation, CI, or development work only.
Related: #2178
Summary by CodeRabbit#
- Bug Fixes
- Paced mutations now use callbacks from the latest committed render, preventing callbacks from an uncommitted, suspended render from affecting active mutations.
- Callback updates are available before descendant layout effects run, while the
mutatefunction remains stable.
- Tests
- Added coverage for callback behavior across suspended and committed renders, descendant layout effects, and StrictMode.
- Documentation
- Updated contributor guidance to describe paced-mutation coverage and its remaining gaps.
- 1
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: defaults
- Review profile: CHILL
- Plan: Advanced
- Run ID:
2f24a601-0360-40e5-a5c4-2a19486effe8
📥 Commits
-
Reviewing files that changed from the base of the PR and between 6d176225cdcac2547ec04c7df86c0a5b8bc0c88f and 81d14ad65f5d549dfe60faa3f5c82f8b0c31847e.
📒 Files selected for processing: 3
-
docs/contributing/oracle-coverage.mddocs/contributing/oracle-reviews/pr-2170-react-paced-render-cuts.mdpackages/react-db/tests/usePacedMutations-render-cuts-oracle.test.tsx
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
-
📝 Walkthrough
-
usePacedMutationsnow publishes callback refs after commit. A React oracle tests callback ownership across suspended and committed renders, descendant layout effects, delayed and immediate persistence, and StrictMode. Documentation records the oracle’s coverage and limits.Changes: Paced mutation callbacks
Layer / File(s) Summary Update callbacks after commit
packages/react-db/src/usePacedMutations.ts,.changeset/tidy-documents-commit.mdusePacedMutationsupdates both callback refs inuseInsertionEffect. Its documentation describes callback ownership by the latest committed render.Test concurrent mutation behavior
packages/react-db/tests/usePacedMutations-render-cuts-oracle.test.tsx,docs/contributing/oracle-coverage.md,docs/contributing/oracle-reviews/pr-2170-react-paced-render-cuts.mdThe oracle checks callback traces, collection rows, and stable mutateidentity across bounded render histories with and without StrictMode. The documentation records the oracle’s coverage, calibration, and limits.Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
81d14-
No actionable merge-blocking issue was identified; the change is ready for normal checks.
Pre-merge checks:
4 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Docstring Coverage Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 3 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold. Passed checks: 4 passed-
Check name Status Explanation Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Title check The title clearly identifies the main change: keeping React DB paced-mutation callbacks tied to committed renders. Description check The description explains the motivation, implementation, test coverage, release impact, and changeset. It uses equivalent headings instead of the template headings and does not include the exact `pnpm…
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 3 files. (2 skipped: 2 unsupported.)
-
- Fix all pre-merge checks with AI
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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 `@coderabbitai help` to get the list of available commands.-
More templates
- todos
- offline-first-electron
- @tanstack/db-example-react-action-enforcement
- @tanstack/db-example-react-next-ssr-e2e
- tanstack-start-example-basic
- @tanstack/db-example-paced-mutations-demo
- tanstack-start-db-projects-example
- @tanstack/db-example-react-start-ssr-e2e
- @tanstack/db-example-react-todo
- offline-transactions-react-native
- shopping-list-react-native
- @tanstack/db-example-solid-todo
@tanstack/angular-db
npm i https://pkg.pr.new/@tanstack/angular-db@2170@tanstack/browser-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/browser-db-sqlite-persistence@2170@tanstack/capacitor-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/capacitor-db-sqlite-persistence@2170@tanstack/cloudflare-durable-objects-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/cloudflare-durable-objects-db-sqlite-persistence@2170@tanstack/db
npm i https://pkg.pr.new/@tanstack/db@2170@tanstack/db-ivm
npm i https://pkg.pr.new/@tanstack/db-ivm@2170@tanstack/db-sqlite-persistence-core
npm i https://pkg.pr.new/@tanstack/db-sqlite-persistence-core@2170@tanstack/electric-db-collection
npm i https://pkg.pr.new/@tanstack/electric-db-collection@2170@tanstack/electron-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/electron-db-sqlite-persistence@2170@tanstack/expo-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/expo-db-sqlite-persistence@2170@tanstack/node-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/node-db-sqlite-persistence@2170@tanstack/offline-transactions
npm i https://pkg.pr.new/@tanstack/offline-transactions@2170@tanstack/powersync-db-collection
npm i https://pkg.pr.new/@tanstack/powersync-db-collection@2170@tanstack/query-db-collection
npm i https://pkg.pr.new/@tanstack/query-db-collection@2170@tanstack/react-db
npm i https://pkg.pr.new/@tanstack/react-db@2170@tanstack/react-native-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/react-native-db-sqlite-persistence@2170@tanstack/react-router-with-db
npm i https://pkg.pr.new/@tanstack/react-router-with-db@2170@tanstack/rxdb-db-collection
npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@2170@tanstack/solid-db
npm i https://pkg.pr.new/@tanstack/solid-db@2170@tanstack/svelte-db
npm i https://pkg.pr.new/@tanstack/svelte-db@2170@tanstack/tauri-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/tauri-db-sqlite-persistence@2170@tanstack/trailbase-db-collection
npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@2170@tanstack/vue-db
npm i https://pkg.pr.new/@tanstack/vue-db@2170commit:
81d14adKyleAMathews merged thisedbf4e4
KyleAMathews closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 81d14ad65f5d549dfe60faa3f5c82f8b0c31847e
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
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