Skip to content

Commit c8a8f2f

Browse files
authored
Be more tolerant of errors triggered by store reset (#1538)
1 parent 2d5e2db commit c8a8f2f

File tree

8 files changed

+27
-5
lines changed

8 files changed

+27
-5
lines changed

.changeset/bright-impalas-teach.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"apollo-client-devtools": patch
3+
---
4+
5+
Fix issue when serializing an `ApolloError` where clientErrors or protocolErrors is undefined.

.changeset/three-toes-teach.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"apollo-client-devtools": patch
3+
---
4+
5+
Fix issue where a page refresh would sometimes cause an error to be displayed in the devtools related to store resets.

src/application/components/Cache/Cache.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { getRootCacheIds } from "./common/utils";
2424
import HighlightMatch from "../HighlightMatch";
2525
import { useActorEvent } from "../../hooks/useActorEvent";
2626
import { PageSpinner } from "../PageSpinner";
27+
import { isIgnoredError } from "../../utilities/ignoredErrors";
2728

2829
const { Sidebar, Main } = SidebarLayout;
2930

@@ -72,7 +73,7 @@ export function Cache({ clientId }: CacheProps) {
7273
}
7374
);
7475

75-
if (error) {
76+
if (error && !isIgnoredError(error)) {
7677
throw error;
7778
}
7879

src/application/components/Mutations/Mutations.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { useActorEvent } from "../../hooks/useActorEvent";
2323
import { SearchField } from "../SearchField";
2424
import HighlightMatch from "../HighlightMatch";
2525
import { PageSpinner } from "../PageSpinner";
26+
import { isIgnoredError } from "../../utilities/ignoredErrors";
2627

2728
const GET_MUTATIONS: TypedDocumentNode<GetMutations, GetMutationsVariables> =
2829
gql`
@@ -76,7 +77,7 @@ export const Mutations = ({ clientId, explorerIFrame }: MutationsProps) => {
7677
}
7778
);
7879

79-
if (error) {
80+
if (error && !isIgnoredError(error)) {
8081
throw error;
8182
}
8283

src/application/components/Queries/Queries.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { useActorEvent } from "../../hooks/useActorEvent";
2525
import { SearchField } from "../SearchField";
2626
import HighlightMatch from "../HighlightMatch";
2727
import { PageSpinner } from "../PageSpinner";
28+
import { isIgnoredError } from "../../utilities/ignoredErrors";
2829

2930
enum QueryTabs {
3031
Variables = "Variables",
@@ -80,7 +81,7 @@ export const Queries = ({ clientId, explorerIFrame }: QueriesProps) => {
8081
}
8182
);
8283

83-
if (error) {
84+
if (error && !isIgnoredError(error)) {
8485
throw error;
8586
}
8687

src/application/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect } from "react";
22
import { createRoot } from "react-dom/client";
33
import type { Reference } from "@apollo/client";
4+
import { loadDevMessages, loadErrorMessages } from "@apollo/client/dev";
45
import { ApolloClient, ApolloProvider, InMemoryCache } from "@apollo/client";
56
import { SchemaLink } from "@apollo/client/link/schema";
67

@@ -12,6 +13,9 @@ import * as Tooltip from "@radix-ui/react-tooltip";
1213
import { getRpcClient } from "../extension/devtools/panelRpcClient";
1314
import { createSchemaWithRpcClient } from "./schema";
1415

16+
loadDevMessages();
17+
loadErrorMessages();
18+
1519
const rpcClient = getRpcClient();
1620
const schema = createSchemaWithRpcClient(rpcClient);
1721
const link = new SchemaLink({ schema });
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const IGNORED_ERRORS = [/^Store reset/];
2+
3+
export function isIgnoredError(error: Error) {
4+
return IGNORED_ERRORS.some((regex) => regex.test(error.message));
5+
}

src/extension/tab/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ export function getQueries(
9797

9898
function serializeApolloError(error: ApolloError): SerializedApolloError {
9999
return {
100-
clientErrors: error.clientErrors.map((e) => e.message),
100+
clientErrors: error.clientErrors?.map((e) => e.message) ?? [],
101101
name: "ApolloError",
102102
networkError: error.networkError
103103
? serializeError(error.networkError)
104104
: undefined,
105105
message: error.message,
106106
graphQLErrors: error.graphQLErrors,
107-
protocolErrors: error.protocolErrors.map((e) => e.message),
107+
protocolErrors: error.protocolErrors?.map((e) => e.message) ?? [],
108108
};
109109
}
110110

0 commit comments

Comments
 (0)