Repository navigation
Description
- I've validated the bug against the latest version of DB packages (
mainatce0b4a98,@tanstack/angular-db@0.2.10).
Describe the bug
A live-query collection created by injectLiveQuery is never cleaned up, either when a params change replaces it or when its injector is destroyed. It loses every subscriber but stays ready indefinitely.
In our app, a scroll-windowed grid changes params on every scroll stop. Each stop leaves one collection behind, and they pile up for the rest of the session.
To Reproduce
Save this as packages/angular-db/tests/gc.test.ts and run it:
import { signal } from '@angular/core'
import { TestBed } from '@angular/core/testing'
import { expect, it } from 'vitest'
import { createCollection, gt } from '@tanstack/db'
import { injectLiveQuery } from '../src/index'
import { mockSyncCollectionOptions } from '../../db/tests/utils'
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
it(`cleans up a live-query collection replaced by a params change`, async () => {
const people = createCollection(
mockSyncCollectionOptions({
id: `people`,
getKey: (p: { id: string; age: number }) => p.id,
initialData: [{ id: `1`, age: 20 }],
}),
)
const minAge = signal(10)
const replaced = await TestBed.runInInjectionContext(async () => {
const result = injectLiveQuery({
params: () => ({ minAge: minAge() }),
query: ({ params, q }) =>
q.from({ p: people }).where(({ p }) => gt(p.age, params.minAge)),
})
TestBed.tick()
await wait(10)
const first = result.collection()!
minAge.set(15)
TestBed.tick()
await wait(10)
return first
})
expect(replaced.subscriberCount).toBe(0) // passes
await wait(200)
expect(replaced.status).toBe(`cleaned-up`) // fails: still `ready`
})The same thing happens on destroy. A collection whose injector has been destroyed also has 0 subscribers and also stays ready.
Expected behavior
A collection is cleaned up once nothing subscribes to it, as useLiveQuery in react-db does.
Cause
injectLiveQuery passes gcTime: 0 in all three of its forms (index.ts:185, 208, 215). A non-positive gcTime turns GC off (lifecycle.ts:311), and the adapter never calls cleanup() itself.
react-db had the same gcTime: 0 until #535 changed it to DEFAULT_GC_TIME_MS = 1 // … (0 disables GC). angular-db was added six days earlier (#424) and never got that change.
We tested the same fix in angular-db: a DEFAULT_GC_TIME_MS = 1 constant in place of the three zeros. The test above then passes, the destroy case is fixed too, and the existing suite still passes (63 passed, 1 todo). Until it's fixed upstream, we carry this as a pnpm patch.
Activity
github-actions commentedon Oct 18, 2026
🎉 The PR fixing this issue (#2172) has been released!
Thank you for reporting!