Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lemon-fireants-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Prevent the `setTimeout` in `connectToDevtools` that shows the devtools suggestion from firing when the user agent does not match Chrome or Firefox. This check was previously done inside the `setTimeout` which meant the timer was scheduled for environments where we'd never show the message anyways. For test environments, this could cause flaky tests when that `setTimeout` outlived the tests and ran after any virtual DOM was torn down and removed.
50 changes: 26 additions & 24 deletions src/core/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1169,33 +1169,35 @@ export class ApolloClient {
*/
if (!hasSuggestedDevtools && __DEV__) {
hasSuggestedDevtools = true;
const win = window;

const ua = win.navigator.userAgent;
let url: string | undefined;

if (typeof ua === "string") {
if (ua.indexOf("Chrome/") > -1) {
url =
"https://chrome.google.com/webstore/detail/" +
"apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm";
} else if (ua.indexOf("Firefox/") > -1) {
url =
"https://addons.mozilla.org/en-US/firefox/addon/apollo-developer-tools/";
}
}

if (
window.document &&
window.top === window.self &&
/^(https?|file):$/.test(window.location.protocol)
win.document &&
win.top === win.self &&
/^(https?|file):$/.test(win.location.protocol) &&
url
) {
setTimeout(() => {
if (!(window as any).__APOLLO_DEVTOOLS_GLOBAL_HOOK__) {
const nav = window.navigator;
const ua = nav && nav.userAgent;
let url: string | undefined;
if (typeof ua === "string") {
if (ua.indexOf("Chrome/") > -1) {
url =
"https://chrome.google.com/webstore/detail/" +
"apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm";
} else if (ua.indexOf("Firefox/") > -1) {
url =
"https://addons.mozilla.org/en-US/firefox/addon/apollo-developer-tools/";
}
}
if (url) {
invariant.log(
"Download the Apollo DevTools for a better development " +
"experience: %s",
url
);
}
if (!(win as any).__APOLLO_DEVTOOLS_GLOBAL_HOOK__) {
invariant.log(
"Download the Apollo DevTools for a better development " +
"experience: %s",
url
);
}
}, 10000);
}
Expand Down
Loading