Repository navigation
Conversation
|
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
fredericoo
left a comment
There was a problem hiding this comment.
some caveats with nextjs (headers already sent, so it doesn't matter there)
fredericoo
left a comment
There was a problem hiding this comment.
left a long comment about the follow-up to get things working as expected. pls work on that so we can release the next version with everything working properly
0172dc8 to
4e1cb2b
Compare
|
@fredericoo I read the comment and agree. I updated to mark get as personalized with no Also, a rate-limited Ill follow up with no2 before merging this one as well |
4e1cb2b to
00bf1a5
Compare
📦 Bundle size report
Unchanged (13)
How this is measuredEach scenario is bundled from the built package with Rolldown (tree-shaken, minified, dynamic imports inlined), then gzipped. Peer dependencies are external. Scenarios live in 🟢 smaller · 🟡 larger (< 5%) · 🔴 larger (≥ 5%) · 🆕 not in base · ❌ failed to bundle · ⚪ unchanged |
00bf1a5 to
f0427fc
Compare
cartHandlers.get() now marks the request context personalized when the request has a cart ID, so applyResponseHeaders() makes the response private and uncacheable. Also exposes markResponseAsPersonalized() publicly and documents it in the cart UI skill references.
Next sends page headers from proxy.ts before Server Components render, and AppShell reads the cart on its own request context, so the cart GET handler's mark never reached the page. Next keeps a Cache-Control header set in proxy.ts, so a public cache header would apply to pages carrying the buyer's cart ID. Mark the response in proxy.ts when the request has a cart ID, and update the Next.js skill references and storefront contract.
A page cached for a visitor without a cart carries `{cart: null}`, which tells
`CartProvider` not to fetch `/api/cart`. A buyer with a cart who gets that cached
page sees an empty cart. `cartHandlers.get()` now marks the response personalized
on every call, not only when the request has a cart ID, and the Next.js example
proxy marks every request to match.
The cart GET marks its response personalized before it fetches, and applyResponseHeaders applies the private value after the 429 no-store, as it already does for Customer Account requests. The #4282 test asserted plain no-store for a rate-limited GET, so it now asserts the private value, and the applyResponseHeaders docs say a marked response keeps it.
f0427fc to
db6b143
Compare
TL;DR:
cartHandlers.get()now marks the response as private, so a cached cart response can't be served to other users.When a loader keeps only the
datafromcartHandlers.get(), the handler's private cache headers are dropped. The page or React Router.dataresponse then stays cacheable, and a shared cache can hand one user's cart to other users.Before
After
What this changes
cartHandlers.get()callsmarkResponseAsPersonalized()before it fetches the cart when the request has a cart ID (cartcookie orcartIdsearch parameter). Marking first covers loaders that stream the cart promise.requestContext.markResponseAsPersonalized(reason)is now exported, for pages that render a cart fromgetCart()or from a separate/api/cartrequest.proxy.tsmarks the response whengetCartId(request)finds a cart ID. Next sends page headers fromproxy.tsbefore Server Components render, andAppShellreads the cart on its own request context, so the handler's mark never reaches the page. Next makes dynamic pages private by default, but it keeps aCache-Controlheader set inproxy.ts, so a merchant's public cache header would apply to a page carrying the buyer's cart ID and key..datarequests, reads without arequest, no cart ID, an expired cart cookie, and a streamed cart read.Developer impact
Includes a patch changeset for the handler behavior and a minor changeset for the new public
markResponseAsPersonalized().getCart()doesn't mark the response. CallmarkResponseAsPersonalized()yourself when:getCart()directly/api/cartas a separate request (such as NuxtuseFetch)proxy.ts)Out of scope
{cart: null}, which tells the client not to fetch/api/cart. A buyer with acartcookie who gets that cached page sees an empty cart. This predates the PR and will be a follow-up: the client store fetches/api/cartwhen it gets{cart: null}but the browser has acartcookie.Vary: Cookiedoesn't work here: Oxygen keys on the whole cookie header, so every visitor gets a separate cache entry, and Cloudflare ignoresVaryby default.Risk
cartcookie for an expired or completed cart still makes the response private. That is intentional.How to Test
pnpm build:pkgs, thencd examples/nextjs && pnpm build && pnpm start -p 3417.curl -si -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Origin: http://localhost:3417' -d '{"action":"add","lines":[{"merchandiseId":"gid://shopify/ProductVariant/43695710371862","quantity":1}]}' http://localhost:3417/api/cart, and copy thecart=…value fromset-cookie.response.headers.set("Cache-Control", "public, s-maxage=60")beforerequestContext.applyResponseHeaders()inexamples/nextjs/proxy.ts, then rebuild and restart.curl -s -o /dev/null -D - -H 'Cookie: cart=<value>' http://localhost:3417/products/slides. Confirmcache-control: private, no-store, max-age=0, must-revalidate.cache-control: public, s-maxage=60.