-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2208 from iFixit/memoize-app-router-find-product
Memoize app router find product
- Loading branch information
Showing
6 changed files
with
92 additions
and
53 deletions.
There are no files selected for viewing
30 changes: 13 additions & 17 deletions
30
frontend/app/(defaultLayout)/@storeSelect/products/app-router/[handle]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'server-only'; | ||
|
||
import { DEFAULT_STORE_CODE } from '@config/env'; | ||
import Product from '@pages/api/nextjs/cache/product'; | ||
import { ifixitOrigin } from 'app/_helpers/app-helpers'; | ||
import { cache } from 'react'; | ||
|
||
interface FindProductArgs { | ||
handle: string; | ||
noCache: boolean; | ||
} | ||
|
||
export async function findProduct({ handle, noCache }: FindProductArgs) { | ||
const result = await findProductOrRedirect(handle, noCache); | ||
if (result?.__typename === 'Product') return result; | ||
return null; | ||
} | ||
|
||
export async function findProductRedirect({ | ||
handle, | ||
noCache, | ||
}: FindProductArgs) { | ||
const result = await findProductOrRedirect(handle, noCache); | ||
if (result?.__typename === 'ProductRedirect') return result; | ||
return null; | ||
} | ||
|
||
const findProductOrRedirect = cache( | ||
async (handle: string, skipCache: boolean) => { | ||
return await Product.get( | ||
{ | ||
handle, | ||
storeCode: DEFAULT_STORE_CODE, | ||
ifixitOrigin: ifixitOrigin(), | ||
}, | ||
{ forceMiss: skipCache } | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ce1ed13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
react-commerce-prod – ./frontend
react-commerce-prod-ifixit.vercel.app
react-commerce-prod-git-main-ifixit.vercel.app
react-commerce-prod.vercel.app
ce1ed13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
react-commerce – ./frontend
react-commerce-git-main-ifixit.vercel.app
react-commerce-ifixit.vercel.app
react-commerce.vercel.app