Skip to content

Commit

Permalink
Fix storefront api cache key (#1375)
Browse files Browse the repository at this point in the history
  • Loading branch information
wizardlyhel authored Sep 26, 2023
1 parent 06da557 commit bfb142e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-jars-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen': patch
---

Fix storefront sub request cache key
19 changes: 19 additions & 0 deletions packages/hydrogen/src/storefront.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,28 @@ export function createStorefrontClient<TI18n extends I18nBase>(
}),
};

// Remove any headers that are identifiable to the user or request
const cacheKey = [
url,
{
method: requestInit.method,
headers: {
'content-type': defaultHeaders['content-type'],
'X-SDK-Variant': defaultHeaders['X-SDK-Variant'],
'X-SDK-Variant-Source': defaultHeaders['X-SDK-Variant-Source'],
'X-SDK-Version': defaultHeaders['X-SDK-Version'],
'X-Shopify-Storefront-Access-Token':
defaultHeaders['X-Shopify-Storefront-Access-Token'],
'user-agent': defaultHeaders['user-agent'],
},
body: requestInit.body,
},
];

const [body, response] = await fetchWithServerCache(url, requestInit, {
cacheInstance: mutation ? undefined : cache,
cache: cacheOptions || CacheShort(),
cacheKey,
shouldCacheResponse: checkGraphQLErrors,
waitUntil,
});
Expand Down

0 comments on commit bfb142e

Please sign in to comment.