Cart metafields: app-owned route + skill (stacked on #3967) - #3968
Open
andguy95 wants to merge 1 commit into
Open
Cart metafields: app-owned route + skill (stacked on #3967)#3968andguy95 wants to merge 1 commit into
andguy95 wants to merge 1 commit into
Conversation
andguy95
marked this pull request as ready for review
August 22, 2026 00:05
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.
Stacked on #3967 (cart refresh API). This PR is based on
an-cart-refresh-util;TL;DR: Cart metafields are server-only — the Storefront cart ajax API (Standard Actions) does not support them, so they can't flow through Hydrogen's optimistic cart store. Instead of teaching the core cart API about metafields, this demonstrates the composable pattern: read through a custom
CartFragment, write through an app-owned route, and re-sync withrefresh().What this changes
POST /api/cart/metafieldsroute in the Hydrogen example. It runscartMetafieldsSetfor an existing cart,cartCreate(with the metafields) when no cart exists yet, andcartMetafieldDeletefor a single key. It returns only the mutationuserErrors— it never refetches and returns the cart.CartFragmenton the cart server handlers.CartSummarythat writes via the route and callsuseCartActions().refresh()on success. No component-local metafield state.hydrogen-cart-metafieldsskill and cross-links it fromhydrogen-cart-ui..docs/dependencies.md.Why decouple the write from the read
The mutation route returns only
userErrors; re-syncing is a separaterefresh()call. This keeps a successful save from being reported as a "network error" when a later read blips — a failed re-sync surfaces aserrors.networkand preserves the saved cart, never as a failed save.Developer impact
hydrogen-cart-metafields) that ships in@shopify/hydrogen, plus a one-line cross-reference inhydrogen-cart-ui. No new exports or runtime APIs.UX impact
Out of scope
How to Test
pnpm install, thenpnpm --filter @shopify/hydrogen build.pnpm --dir examples/hydrogen devand open the printed local URL.