fix(db-ivm): treat 0 and empty string as valid min/max extremes - #1809
Conversation
min() and max() used truthiness to detect an unset accumulator, so 0, 0n, and "" were skipped or overwritten. Compare against undefined. Fixes TanStack#1775
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe ChangesFalsy min/max aggregate handling
Priority: ⚪ Not assessed Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk: ⚪ Minimal · up to The falsy-extrema change appears mergeable after normal checks. 🚥 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 |
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/react-router-with-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Fix
@tanstack/db-ivmmin/max aggregation so numeric zero and bigint zero remain valid minima or maxima, and the empty string remains a valid string minimum. Grouped live-query results no longer silently replace these falsy extrema with later values.Root Cause
The reducers used truthiness both as the “no accumulator yet” sentinel and as a guard around comparisons. That made
0,0n, and""indistinguishable from an unset accumulator: a falsy extreme could be skipped when encountered later or overwritten by the next truthy value.Approach
undefinedas an unset accumulator.undefinedreducer entries before comparing values, preserving the aggregate's declared input type.sum,min, andmaxdeltas and retained state with independent full recomputation.Key Invariants
undefinednever becomes a min/max candidate.undefined.Non-goals
@tanstack/db-ivm.RED/GREEN Verification
0and-1.minimum: 5instead of0andmaximum: -2instead of0under the old code.@tanstack/db-ivmsuite: 39 files and 559 tests passed.Files changed
packages/db-ivm/src/operators/groupBy.ts— use explicitundefinedguards for min/max reduction.packages/db-ivm/tests/operators/groupBy.test.ts— retain readable reducer and pipeline replay witnesses.packages/db-ivm/tests/incrementalization-law.property.test.ts— add independent min/max recomputation, fixed/random/replay histories, named reach, and the exact truthiness mutant..changeset/minmax-falsy-extremes.md— publish the correction as a patch.Fixes #1775
Summary by CodeRabbit
Bug Fixes
minandmaxgrouping results so valid falsy values—including0,0n, and empty strings—are correctly considered.Tests