Skip to content

Commit

Permalink
Remove fetchWithServerCache export and move injected fetch directly u…
Browse files Browse the repository at this point in the history
…nder context
  • Loading branch information
frandiox committed Nov 9, 2022
1 parent 27ad1ee commit 162e2d4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
1 change: 0 additions & 1 deletion packages/@hydrogen/remix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {Params} from '@remix-run/react';
export * from '@remix-run/oxygen';
export {createRequestHandler} from './server';
export * from './storefront';
export {fetchWithServerCache} from './cache/fetch';
export {
CacheNone,
CacheShort,
Expand Down
6 changes: 3 additions & 3 deletions packages/@hydrogen/remix/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ export function createRequestHandler(
return await handleRequest(request, {
...options,
context: {
...context,
cache,
storefront: createStorefrontClient(storefront, {
...createStorefrontClient(storefront, {
cache,
buyerIp: getBuyerIp(request),
waitUntil: (p: Promise<any>) => context.waitUntil(p),
}),
...context,
cache,
},
});
} catch (e) {
Expand Down
30 changes: 18 additions & 12 deletions packages/@hydrogen/remix/storefront.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,31 @@ export function createStorefrontClient(
}

return {
query: getStorefrontData,
getPublicTokenHeaders,
getPrivateTokenHeaders,
getStorefrontApiUrl,
cache,
CacheNone,
CacheLong,
CacheShort,
CacheCustom,
storefront: {
query: getStorefrontData,
getPublicTokenHeaders,
getPrivateTokenHeaders,
getStorefrontApiUrl,
cache,
CacheNone,
CacheLong,
CacheShort,
CacheCustom,
},
fetch: (
url: string,
requestInit: RequestInit,
fetchOptions: Omit<FetchCacheOptions, 'cacheInstance' | 'waitUntil'>,
{
hydrogen,
...requestInit
}: RequestInit & {
hydrogen?: Omit<FetchCacheOptions, 'cacheInstance' | 'waitUntil'>;
},
) =>
fetchWithServerCache(url, requestInit, {
waitUntil,
cacheKey: [url, requestInit],
cacheInstance: cache,
...fetchOptions,
...hydrogen,
}),
};
}
Expand Down

0 comments on commit 162e2d4

Please sign in to comment.