Skip to content
Source
Sign inSign up
TanStack/query

fix(query-core): recompute placeholders when select changes #11535

Closedbrennanbutler01(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/11535/headopened View on GitHub

Showing 4 changed files with 41 additions and 1 deletion (loading 1).

x
0 of 4 viewed, 4 left
5 additions and 0 deletions.changeset/placeholder-select-fix.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+"@tanstack/query-core": patch
+---
+​
+Recompute selected placeholder data when the selector changes or is removed.
34 additions and 0 deletionspackages/query-core/src/__tests__/queryObserver.test.tsxModified
View file
@@ -24,6 +24,40 @@
vi.useRealTimers()
})
​
+ it.each([false, true])(
+ 'should update selected placeholder data when select changes (function: %s)',
+ (functional) => {
+ const key = queryKey()
+ const placeholderData = functional ? () => 2 : 2
+ const options = {
+ queryKey: key,
+ queryFn: () => 2,
+ enabled: false,
+ placeholderData,
+ }
+ const observer = new QueryObserver(queryClient, {
+ ...options,
+ select: (value) => value * 2,
+ })
+ expect(observer.getCurrentResult().data).toBe(4)
+ observer.setOptions({ ...options, select: (value) => value * 3 })
+ expect(observer.getCurrentResult()).toMatchObject({