This repository was archived by the owner on Mar 14, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +22
-12
lines changed Expand file tree Collapse file tree 4 files changed +22
-12
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte-query-pocketbase ' : patch
3
+ ---
4
+
5
+ fix: change how queries are invalidated
Original file line number Diff line number Diff line change @@ -179,10 +179,15 @@ export const createCollectionQuery = <
179
179
await unsubscribePromise
180
180
) ( ) ;
181
181
if (
182
- ! collection . client . realtime [ 'hasSubscriptionListeners' ] ( collection . collectionIdOrName )
182
+ ! collection . client . realtime [ 'hasSubscriptionListeners' ] (
183
+ collection . collectionIdOrName
184
+ ) ||
185
+ Object . keys ( queryParams ?? { } ) . length > 0
183
186
) {
184
187
console . log (
185
- `(C) ${ JSON . stringify ( queryKey ) } : no realtime listeners, marking query as stale.`
188
+ `(C) ${ JSON . stringify (
189
+ queryKey
190
+ ) } : no realtime listeners or query has queryParams, marking query as stale.`
186
191
) ;
187
192
queryClient . invalidateQueries ( { queryKey, exact : true } ) ;
188
193
}
Original file line number Diff line number Diff line change @@ -303,14 +303,8 @@ export const createInfiniteCollectionQuery = <
303
303
await (
304
304
await unsubscribePromise
305
305
) ( ) ;
306
- if (
307
- ! collection . client . realtime [ 'hasSubscriptionListeners' ] ( collection . collectionIdOrName )
308
- ) {
309
- console . log (
310
- `(IC) ${ JSON . stringify ( queryKey ) } : no realtime listeners, marking query as stale.`
311
- ) ;
312
- queryClient . invalidateQueries ( { queryKey, exact : true } ) ;
313
- }
306
+ console . log ( `(IC) ${ JSON . stringify ( queryKey ) } : marking query as stale.` ) ;
307
+ queryClient . invalidateQueries ( { queryKey, exact : true } ) ;
314
308
} ) ( ) ;
315
309
return unsubscriber ( ) ;
316
310
} ;
Original file line number Diff line number Diff line change @@ -172,11 +172,17 @@ export const createRecordQuery = <
172
172
if (
173
173
! collection . client . realtime [ 'hasSubscriptionListeners' ] (
174
174
`${ collection . collectionIdOrName } /${ id } `
175
- )
175
+ ) ||
176
+ Object . keys ( queryParams ?? { } ) . length > 0
176
177
) {
177
178
console . log (
178
- `(R) ${ JSON . stringify ( queryKey ) } : no realtime listeners, marking query as stale.`
179
+ `(R) ${ JSON . stringify (
180
+ queryKey
181
+ ) } : no realtime listeners or query has queryParams, marking query as stale.`
179
182
) ;
183
+ // todo: correctly derive queryKey to mark as invalid
184
+ // todo: ensure that if a $store was passed into filterFunction,
185
+ // only the value when query was created with is used even after the $store's value changes
180
186
queryClient . invalidateQueries ( { queryKey, exact : true } ) ;
181
187
}
182
188
} ) ( ) ;
You can’t perform that action at this time.
0 commit comments