@@ -70,7 +70,7 @@ interface InternalQueryResult<TData, TVariables extends OperationVariables>
70
70
[ originalResult ] : ApolloQueryResult < TData > ;
71
71
}
72
72
73
- const noop = ( ) => { } ;
73
+ function noop ( ) { }
74
74
export const lastWatchOptions = Symbol ( ) ;
75
75
76
76
export interface ObsQueryWithMeta < TData , TVariables extends OperationVariables >
@@ -213,20 +213,6 @@ function useInternalState<
213
213
let [ internalState , updateInternalState ] =
214
214
React . useState ( createInternalState ) ;
215
215
216
- if ( client !== internalState . client || query !== internalState . query ) {
217
- // If the client or query have changed, we need to create a new InternalState.
218
- // This will trigger a re-render with the new state, but it will also continue
219
- // to run the current render function to completion.
220
- // Since we sometimes trigger some side-effects in the render function, we
221
- // re-assign `state` to the new state to ensure that those side-effects are
222
- // triggered with the new state.
223
- const newInternalState = createInternalState ( internalState ) ;
224
- updateInternalState ( newInternalState ) ;
225
- return [ newInternalState , onQueryExecuted ] as const ;
226
- }
227
-
228
- return [ internalState , onQueryExecuted ] as const ;
229
-
230
216
/**
231
217
* Used by `useLazyQuery` when a new query is executed.
232
218
* We keep this logic here since it needs to update things in unsafe
@@ -253,6 +239,20 @@ function useInternalState<
253
239
} ) ,
254
240
} ) ;
255
241
}
242
+
243
+ if ( client !== internalState . client || query !== internalState . query ) {
244
+ // If the client or query have changed, we need to create a new InternalState.
245
+ // This will trigger a re-render with the new state, but it will also continue
246
+ // to run the current render function to completion.
247
+ // Since we sometimes trigger some side-effects in the render function, we
248
+ // re-assign `state` to the new state to ensure that those side-effects are
249
+ // triggered with the new state.
250
+ const newInternalState = createInternalState ( internalState ) ;
251
+ updateInternalState ( newInternalState ) ;
252
+ return [ newInternalState , onQueryExecuted ] as const ;
253
+ }
254
+
255
+ return [ internalState , onQueryExecuted ] as const ;
256
256
}
257
257
258
258
export function useQueryInternals <
@@ -405,8 +405,11 @@ function useObservableSubscriptionResult<
405
405
} ;
406
406
407
407
const onError = ( error : Error ) => {
408
- subscription . unsubscribe ( ) ;
409
- subscription = observable . resubscribeAfterError ( onNext , onError ) ;
408
+ subscription . current . unsubscribe ( ) ;
409
+ subscription . current = observable . resubscribeAfterError (
410
+ onNext ,
411
+ onError
412
+ ) ;
410
413
411
414
if ( ! hasOwnProperty . call ( error , "graphQLErrors" ) ) {
412
415
// The error is not a GraphQL error
@@ -436,14 +439,19 @@ function useObservableSubscriptionResult<
436
439
}
437
440
} ;
438
441
439
- let subscription = observable . subscribe ( onNext , onError ) ;
442
+ // TODO evaluate if we keep this in
443
+ // React Compiler cannot handle scoped `let` access, but a mutable object
444
+ // like this is fine.
445
+ // was:
446
+ // let subscription = observable.subscribe(onNext, onError);
447
+ const subscription = { current : observable . subscribe ( onNext , onError ) } ;
440
448
441
449
// Do the "unsubscribe" with a short delay.
442
450
// This way, an existing subscription can be reused without an additional
443
451
// request if "unsubscribe" and "resubscribe" to the same ObservableQuery
444
452
// happen in very fast succession.
445
453
return ( ) => {
446
- setTimeout ( ( ) => subscription . unsubscribe ( ) ) ;
454
+ setTimeout ( ( ) => subscription . current . unsubscribe ( ) ) ;
447
455
} ;
448
456
} ,
449
457
0 commit comments