File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -517,11 +517,6 @@ export class QueryObserver<
517517 if ( options . select && typeof placeholderData !== 'undefined' ) {
518518 try {
519519 placeholderData = options . select ( placeholderData )
520- placeholderData = replaceData (
521- prevResult ?. data ,
522- placeholderData ,
523- options ,
524- )
525520 this . selectError = null
526521 } catch ( selectError ) {
527522 if ( process . env . NODE_ENV !== 'production' ) {
@@ -534,7 +529,7 @@ export class QueryObserver<
534529
535530 if ( typeof placeholderData !== 'undefined' ) {
536531 status = 'success'
537- data = placeholderData as TData
532+ data = replaceData ( prevResult ?. data , placeholderData , options ) as TData
538533 isPlaceholderData = true
539534 }
540535 }
Original file line number Diff line number Diff line change @@ -505,6 +505,24 @@ describe('queryObserver', () => {
505505 expect ( results [ 1 ] ) . toMatchObject ( { status : 'success' , data : 'data' } )
506506 } )
507507
508+ test ( 'should structurally share placeholder data' , async ( ) => {
509+ const key = queryKey ( )
510+ const observer = new QueryObserver ( queryClient , {
511+ queryKey : key ,
512+ enabled : false ,
513+ queryFn : ( ) => 'data' ,
514+ placeholderData : { } ,
515+ } )
516+
517+ const firstData = observer . getCurrentResult ( ) . data
518+
519+ observer . setOptions ( { placeholderData : { } } )
520+
521+ const secondData = observer . getCurrentResult ( ) . data
522+
523+ expect ( firstData ) . toBe ( secondData )
524+ } )
525+
508526 test ( 'the retrier should not throw an error when reject if the retrier is already resolved' , async ( ) => {
509527 const key = queryKey ( )
510528 let count = 0
You can’t perform that action at this time.
0 commit comments