Next.js example: three storefront clients aligned with use cache#3812
Open
malewis5 wants to merge 1 commit into
Open
Next.js example: three storefront clients aligned with use cache#3812malewis5 wants to merge 1 commit into
use cache#3812malewis5 wants to merge 1 commit into
Conversation
Contributor
|
Thank you Matt! We'll review your PRs and merge soonish, then build on top of your changes 🙏 |
Contributor
|
just one note: we should refrain from calling graphql straight from the browser, so the public client actually has not a lot of use right now (I think) but this is the right implementation! we created the three clients with this in mind, glad you instantly got it |
Author
Agree. Tbh only created it to demonstrate |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Splits the Next.js example's single storefront client into three purpose-built clients, each documented against a specific Next.js
use cacheboundary.use cachestorygetStorefrontClientapp/lib/storefront.tsheaders()→ not cacheable. Useuse cache: privatefor buyer cart / logged-in customer data.sharedRateLimitStorefrontClientapp/lib/storefront.tsuse cache. For non-personalized product / collection / blog pages.publicStorefrontClientapp/lib/public-storefront.tsWhy
Next.js 16's
use cacheanduse cache: privatedirectives draw a hard line between request-time and cacheable data. A single client that always readsheaders()can never enter ause cacheboundary. Separating the clients by their data-access pattern lets each route reach for the right one — and surfaces, for the core@shopify/hydrogenpackage, the distinction between buyer-IP, shared-rate-limit, and public token usage.Changes
app/lib/public-storefront.ts— browser-safe public client.sharedRateLimitStorefrontClienttoapp/lib/storefront.tsforuse cache-able server fetches.use cache/use cache: privateboundary on each client with links to the Next.js docs.🤖 Generated with Claude Code