Skip to content

Commit

Permalink
Return early when window is undefined when connecting to devtools
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jul 23, 2024
1 parent 061cab6 commit cc40595
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/core/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,30 +319,31 @@ export class ApolloClient<TCacheShape> implements DataProxy {
}

private connectToDevTools() {
if (typeof window === "object") {
type DevToolsConnector = {
push(client: ApolloClient<any>): void;
};
const windowWithDevTools = window as Window & {
[devtoolsSymbol]?: DevToolsConnector;
__APOLLO_CLIENT__?: ApolloClient<any>;
};
const devtoolsSymbol = Symbol.for("apollo.devtools");
(windowWithDevTools[devtoolsSymbol] =
windowWithDevTools[devtoolsSymbol] || ([] as DevToolsConnector)).push(
this
);
windowWithDevTools.__APOLLO_CLIENT__ = this;
if (typeof window === "undefined") {
return;
}

type DevToolsConnector = {
push(client: ApolloClient<any>): void;
};
const windowWithDevTools = window as Window & {
[devtoolsSymbol]?: DevToolsConnector;
__APOLLO_CLIENT__?: ApolloClient<any>;
};
const devtoolsSymbol = Symbol.for("apollo.devtools");
(windowWithDevTools[devtoolsSymbol] =
windowWithDevTools[devtoolsSymbol] || ([] as DevToolsConnector)).push(
this
);
windowWithDevTools.__APOLLO_CLIENT__ = this;

/**
* Suggest installing the devtools for developers who don't have them
*/
if (!hasSuggestedDevtools && __DEV__) {
hasSuggestedDevtools = true;
setTimeout(() => {
if (
typeof window !== "undefined" &&
window.document &&
window.top === window.self &&
!(window as any).__APOLLO_DEVTOOLS_GLOBAL_HOOK__ &&
Expand Down

0 comments on commit cc40595

Please sign in to comment.