Skip to content

Commit 15c772f

Browse files
KyleAMathewsclaude
andauthored
Add warning for preload on on-demand collections (#871)
* feat: warn when calling preload() on on-demand collections Calling .preload() on a collection with syncMode "on-demand" is a no-op since data is only loaded when queries request it. This change adds a warning to help users understand this behavior and suggests creating a live query instead. The warning includes a link to the Query-Driven Sync blog post for additional context and guidance. * chore: add changeset for preload on-demand warning --------- Co-authored-by: Claude <[email protected]>
1 parent 6b8d952 commit 15c772f

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tanstack/db": patch
3+
---
4+
5+
Add warning when calling `.preload()` on collections with `on-demand` syncMode. In on-demand mode, data is only loaded when queries request it, so calling `.preload()` on the collection itself is a no-op. Users should create a live query and call `.preload()` on that instead.

packages/db/src/collection/sync.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ export class CollectionSyncManager<
231231
return this.preloadPromise
232232
}
233233

234+
// Warn when calling preload on an on-demand collection
235+
if (this.syncMode === `on-demand`) {
236+
console.warn(
237+
`${this.id ? `[${this.id}] ` : ``}Calling .preload() on a collection with syncMode "on-demand" is a no-op. ` +
238+
`In on-demand mode, data is only loaded when queries request it. ` +
239+
`Instead, create a live query and call .preload() on that to load the specific data you need. ` +
240+
`See https://tanstack.com/blog/tanstack-db-0.5-query-driven-sync for more details.`
241+
)
242+
}
243+
234244
this.preloadPromise = new Promise<void>((resolve, reject) => {
235245
if (this.lifecycle.status === `ready`) {
236246
resolve()

0 commit comments

Comments
 (0)