Skip to content

Commit

Permalink
Be more tolerant of errors triggered by store reset (#1538)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller authored Oct 4, 2024
1 parent 2d5e2db commit c8a8f2f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-impalas-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"apollo-client-devtools": patch
---

Fix issue when serializing an `ApolloError` where clientErrors or protocolErrors is undefined.
5 changes: 5 additions & 0 deletions .changeset/three-toes-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"apollo-client-devtools": patch
---

Fix issue where a page refresh would sometimes cause an error to be displayed in the devtools related to store resets.
3 changes: 2 additions & 1 deletion src/application/components/Cache/Cache.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { getRootCacheIds } from "./common/utils";
import HighlightMatch from "../HighlightMatch";
import { useActorEvent } from "../../hooks/useActorEvent";
import { PageSpinner } from "../PageSpinner";
import { isIgnoredError } from "../../utilities/ignoredErrors";

const { Sidebar, Main } = SidebarLayout;

Expand Down Expand Up @@ -72,7 +73,7 @@ export function Cache({ clientId }: CacheProps) {
}
);

if (error) {
if (error && !isIgnoredError(error)) {
throw error;
}

Expand Down
3 changes: 2 additions & 1 deletion src/application/components/Mutations/Mutations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useActorEvent } from "../../hooks/useActorEvent";
import { SearchField } from "../SearchField";
import HighlightMatch from "../HighlightMatch";
import { PageSpinner } from "../PageSpinner";
import { isIgnoredError } from "../../utilities/ignoredErrors";

const GET_MUTATIONS: TypedDocumentNode<GetMutations, GetMutationsVariables> =
gql`
Expand Down Expand Up @@ -76,7 +77,7 @@ export const Mutations = ({ clientId, explorerIFrame }: MutationsProps) => {
}
);

if (error) {
if (error && !isIgnoredError(error)) {
throw error;
}

Expand Down
3 changes: 2 additions & 1 deletion src/application/components/Queries/Queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useActorEvent } from "../../hooks/useActorEvent";
import { SearchField } from "../SearchField";
import HighlightMatch from "../HighlightMatch";
import { PageSpinner } from "../PageSpinner";
import { isIgnoredError } from "../../utilities/ignoredErrors";

enum QueryTabs {
Variables = "Variables",
Expand Down Expand Up @@ -80,7 +81,7 @@ export const Queries = ({ clientId, explorerIFrame }: QueriesProps) => {
}
);

if (error) {
if (error && !isIgnoredError(error)) {
throw error;
}

Expand Down
4 changes: 4 additions & 0 deletions src/application/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect } from "react";
import { createRoot } from "react-dom/client";
import type { Reference } from "@apollo/client";
import { loadDevMessages, loadErrorMessages } from "@apollo/client/dev";
import { ApolloClient, ApolloProvider, InMemoryCache } from "@apollo/client";
import { SchemaLink } from "@apollo/client/link/schema";

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

loadDevMessages();
loadErrorMessages();

const rpcClient = getRpcClient();
const schema = createSchemaWithRpcClient(rpcClient);
const link = new SchemaLink({ schema });
Expand Down
5 changes: 5 additions & 0 deletions src/application/utilities/ignoredErrors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const IGNORED_ERRORS = [/^Store reset/];

export function isIgnoredError(error: Error) {
return IGNORED_ERRORS.some((regex) => regex.test(error.message));
}
4 changes: 2 additions & 2 deletions src/extension/tab/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ export function getQueries(

function serializeApolloError(error: ApolloError): SerializedApolloError {
return {
clientErrors: error.clientErrors.map((e) => e.message),
clientErrors: error.clientErrors?.map((e) => e.message) ?? [],
name: "ApolloError",
networkError: error.networkError
? serializeError(error.networkError)
: undefined,
message: error.message,
graphQLErrors: error.graphQLErrors,
protocolErrors: error.protocolErrors.map((e) => e.message),
protocolErrors: error.protocolErrors?.map((e) => e.message) ?? [],
};
}

Expand Down

0 comments on commit c8a8f2f

Please sign in to comment.