fix: disable GC on child collections created by includes system#1430
Merged
kevin-dp merged 2 commits intoTanStack:mainfrom Mar 30, 2026
Merged
fix: disable GC on child collections created by includes system#1430kevin-dp merged 2 commits intoTanStack:mainfrom
kevin-dp merged 2 commits intoTanStack:mainfrom
Conversation
Child collections created by the includes system (nested subqueries in .select()) inherit the default gcTime of 5 minutes. When the only React subscriber unmounts (e.g., virtual table scrolling), the collection gets garbage collected and data is permanently lost. This test subscribes to a child collection, unsubscribes (simulating component unmount), advances past the GC timeout, and asserts the data is still intact. It currently fails, proving the bug.
Add gcTime: 0 to createChildCollectionEntry so child collections are not subject to time-based garbage collection. Child collection lifecycle is already managed by flushIncludesState Phase 5, which removes them from childRegistry when parent rows are deleted. External GC is unnecessary and causes permanent data loss when React subscribers unmount (e.g., virtual table scrolling, tab switching, conditional rendering). Fixes TanStack#1429
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/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
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.
Summary
Child collections created by
createChildCollectionEntryinherit the defaultgcTimeof 5 minutes. When React subscribers unmount (virtual table scrolling, tab switching, conditional rendering), the subscriber count drops to 0, GC fires, and data is permanently lost — the includes system has no mechanism to re-populate.Fix
One-line change: add
gcTime: 0to thecreateCollectioncall increateChildCollectionEntry. This disables external GC. Child collection lifecycle is already managed byflushIncludesStatePhase 5.Test
Regression test added: subscribes to a child collection, unsubscribes (simulating unmount), advances past GC timeout, asserts data is intact. Fails without fix, passes with fix.
Fixes #1429