@@ -19,7 +19,7 @@ import {
19
19
getMutations ,
20
20
getMainDefinition ,
21
21
} from "./helpers" ;
22
- import type { QueryResult } from "../../types" ;
22
+ import type { QueryResult , SafeAny } from "../../types" ;
23
23
import { getPrivateAccess } from "../../privateAccess" ;
24
24
import type { JSONObject } from "../../application/types/json" ;
25
25
import { createWindowActor } from "../actor" ;
@@ -91,12 +91,6 @@ window.onbeforeunload = () => {
91
91
tab . send ( { type : "disconnectFromDevtools" } ) ;
92
92
} ;
93
93
94
- window . addEventListener ( "load" , ( ) => {
95
- if ( hook . ApolloClient ) {
96
- sendHookDataToDevTools ( "connectToDevtools" ) ;
97
- }
98
- } ) ;
99
-
100
94
function getClientData ( ) {
101
95
// We need to JSON stringify the data here in case the cache contains
102
96
// references to irregular data such as `URL` instances which are not
@@ -301,4 +295,26 @@ if (Array.isArray(preExisting)) {
301
295
( preExisting as Array < ApolloClient < any > > ) . forEach ( registerClient ) ;
302
296
}
303
297
304
- findClient ( ) ;
298
+ // Handles registering legacy clients (< v3.7) which do not use the new
299
+ // registration mechanism above.
300
+ let globalClient = window . __APOLLO_CLIENT__ ;
301
+ Object . defineProperty ( window , "__APOLLO_CLIENT__" , {
302
+ get ( ) {
303
+ return globalClient ;
304
+ } ,
305
+ set ( client : ApolloClient < SafeAny > | undefined ) {
306
+ if ( client ) {
307
+ // We call this in a setTimeout because the client is not fully
308
+ // instantiated before the property on window is assigned since it
309
+ // connects from the constructor of ApolloClient. This allows
310
+ // initialization to finish before we register it.
311
+ setTimeout ( ( ) => registerClient ( client ) ) ;
312
+ }
313
+
314
+ globalClient = client ;
315
+ } ,
316
+ } ) ;
317
+
318
+ if ( globalClient ) {
319
+ registerClient ( globalClient ) ;
320
+ }
0 commit comments