Skip to content

fix: disable GC on child collections created by includes system#1430

Merged
kevin-dp merged 2 commits intoTanStack:mainfrom
blj:fix/child-collection-gc
Mar 30, 2026
Merged

fix: disable GC on child collections created by includes system#1430
kevin-dp merged 2 commits intoTanStack:mainfrom
blj:fix/child-collection-gc

Conversation

@blj
Copy link
Copy Markdown
Contributor

@blj blj commented Mar 28, 2026

Summary

Child collections created by createChildCollectionEntry inherit the default gcTime of 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: 0 to the createCollection call in createChildCollectionEntry. This disables external GC. Child collection lifecycle is already managed by flushIncludesState Phase 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

blj added 2 commits March 28, 2026 15:17
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
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 30, 2026

More templates

@tanstack/angular-db

npm i https://pkg.pr.new/@tanstack/angular-db@1430

@tanstack/browser-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/browser-db-sqlite-persistence@1430

@tanstack/capacitor-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/capacitor-db-sqlite-persistence@1430

@tanstack/cloudflare-durable-objects-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/cloudflare-durable-objects-db-sqlite-persistence@1430

@tanstack/db

npm i https://pkg.pr.new/@tanstack/db@1430

@tanstack/db-ivm

npm i https://pkg.pr.new/@tanstack/db-ivm@1430

@tanstack/db-sqlite-persistence-core

npm i https://pkg.pr.new/@tanstack/db-sqlite-persistence-core@1430

@tanstack/electric-db-collection

npm i https://pkg.pr.new/@tanstack/electric-db-collection@1430

@tanstack/electron-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/electron-db-sqlite-persistence@1430

@tanstack/expo-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/expo-db-sqlite-persistence@1430

@tanstack/node-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/node-db-sqlite-persistence@1430

@tanstack/offline-transactions

npm i https://pkg.pr.new/@tanstack/offline-transactions@1430

@tanstack/powersync-db-collection

npm i https://pkg.pr.new/@tanstack/powersync-db-collection@1430

@tanstack/query-db-collection

npm i https://pkg.pr.new/@tanstack/query-db-collection@1430

@tanstack/react-db

npm i https://pkg.pr.new/@tanstack/react-db@1430

@tanstack/react-native-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/react-native-db-sqlite-persistence@1430

@tanstack/rxdb-db-collection

npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@1430

@tanstack/solid-db

npm i https://pkg.pr.new/@tanstack/solid-db@1430

@tanstack/svelte-db

npm i https://pkg.pr.new/@tanstack/svelte-db@1430

@tanstack/tauri-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/tauri-db-sqlite-persistence@1430

@tanstack/trailbase-db-collection

npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@1430

@tanstack/vue-db

npm i https://pkg.pr.new/@tanstack/vue-db@1430

commit: 2a13acf

@kevin-dp kevin-dp merged commit d611b94 into TanStack:main Mar 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

includes: child collections get garbage collected, losing data permanently

2 participants