From 73b4dc874103c1693b605deb07e053321fe6a111 Mon Sep 17 00:00:00 2001 From: Bret Little Date: Tue, 26 Mar 2024 07:00:00 -0700 Subject: [PATCH] Make sure 400-500 level HTTP sub-requests are not cached (#1907) --- .changeset/shy-houses-rest.md | 5 +++++ packages/hydrogen/src/cache/fetch.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/shy-houses-rest.md diff --git a/.changeset/shy-houses-rest.md b/.changeset/shy-houses-rest.md new file mode 100644 index 0000000000..ffe6de097d --- /dev/null +++ b/.changeset/shy-houses-rest.md @@ -0,0 +1,5 @@ +--- +'@shopify/hydrogen': patch +--- + +Make sure 400-500 sub-requests are not cached diff --git a/packages/hydrogen/src/cache/fetch.ts b/packages/hydrogen/src/cache/fetch.ts index 386dc950fd..601ece2ace 100644 --- a/packages/hydrogen/src/cache/fetch.ts +++ b/packages/hydrogen/src/cache/fetch.ts @@ -55,7 +55,8 @@ function fromSerializableResponse([body, init]: [any, ResponseInit]) { // Check if the response body has GraphQL errors // https://spec.graphql.org/June2018/#sec-Response-Format -export const checkGraphQLErrors = (body: any) => !body?.errors; +export const checkGraphQLErrors = (body: any, response: Response) => + !body?.errors && response.status < 400; // Lock to prevent revalidating the same sub-request // in the same isolate. Note that different isolates