Skip to content

feat(preview): update cart to add cart attribute support - #3897

Merged
andguy95 merged 5 commits into
previewfrom
an-support-cart-attributes
Aug 14, 2026
Merged

andguy95 merged 5 commits into
previewfrom
an-support-cart-attributes

Conversation

@andguy95

@andguy95 andguy95 commented Jul 31, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR: Adds end-to-end cart attribute support to Hydrogen’s cart primitive, including mutations, optimistic state, scoped errors, examples, and packaged skill guidance.

Dependency: This PR depends on a new Shopify Standard Actions release with cart attribute support. That release must be available before this behavior works end to end.

Before

Hydrogen cart forms supported lines, discount codes, and notes, but did not provide a complete contract for updating cart attributes.

After

Cart forms can submit the complete attribute list:

<input {...register("attributeKey", {value: "gift-message"})} />
<textarea {...register("attributeValue", {defaultValue: message})} />
<button {...register("attributes-update")}>Save message</button>

What this changes

  • Adds cartAttributesUpdate queries and server-handler support.
  • Parses attribute updates from JSON and form submissions.
  • Adds optimistic updates, rollback, pending state, and attribute-scoped errors.
  • Includes attributes in the default cart data and Standard Actions types.
  • Updates analytics handling while attribute mutations are pending.
  • Updates packaged React and Vue cart skill guidance.
  • Adds gift-message examples to the Hydrogen and React Router carts.

Developer impact

Adds the public Attribute and CartAttributeInput types, along with CartData.attributes, pending.attributes, errors.attributes, and the attributes-update form contract.

Attribute updates replace the complete attribute list. Consumers editing one attribute must resubmit unrelated attributes or they will be removed.

No changeset is included because this targets the preview release flow, which assigns the preview package version outside individual PRs. This would otherwise be an additive minor change.

UX impact

The Hydrogen and React Router examples now display a gift-message editor with an attribute-specific saving state.

Risk

  • The corresponding Shopify Standard Actions release must land before this can be tested or used end to end.
  • Incorrectly submitting only one attribute can remove other existing cart attributes.

How to Test

After the Standard Actions release is available:

  1. Run pnpm install && pnpm build:pkgs.
  2. Run pnpm dev:rr.
  3. Open http://localhost:5173, add a product, and open the cart.
  4. Enter and save a gift message.
  5. Confirm the saving state appears and the message persists after reopening the cart and reloading /cart.

@andguy95
andguy95 marked this pull request as ready for review August 10, 2026 22:14
@andguy95
andguy95 requested a review from a team as a code owner August 10, 2026 22:14
@andguy95 andguy95 added the gsd:50917 New Hydrogen label Aug 12, 2026

@frandiox frandiox left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to submit this yesterday 🤦

--

Also, @andguy95 you've probably created more storefronts than myself... any idea what's more common to modify cart attributes, forms or imperative fetches?

Comment thread packages/hydrogen/skills/hydrogen-cart-ui/references/react.md Outdated

@frandiox frandiox left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of minor things but I think this makes sense. Thank you!

(look at this comment above as well just in case #3897 (comment) )

projectAttributeErrors(current, result, payload.attributes, timestampMs),
);
}
if (!result.cart || (result.userErrors?.length ?? 0) > 0) return state;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use result.cart.attributes because the standard action is not supposed to return it, right? But Hydrogen's /api/cart does?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep thats right. For the cart attributes we decided to follow the notes approach where we don't include it in the cart promise return payload

Comment thread examples/hydrogen/app/components/CartSummary.tsx
@andguy95

Copy link
Copy Markdown
Collaborator Author

@frandiox

Also, @andguy95 you've probably created more storefronts than myself... any idea what's more common to modify cart attributes, forms or imperative fetches?

I would say both! It falls into two categories:

  1. Customer facing info -> this would be forms
  • This one is for like gift messages, include gift bag, or delivery messags that require a form like experience
  1. Hidden meta data added to cart -> user fetches
  • This would be like stuffing customer attribution data into cart
  • Session info
  • Or just any data that needs to be added without customer input

@andguy95
andguy95 force-pushed the an-support-cart-attributes branch from f4064c8 to 30db117 Compare August 14, 2026 01:57
@andguy95
andguy95 merged commit bf7700a into preview Aug 14, 2026
5 checks passed
@andguy95
andguy95 deleted the an-support-cart-attributes branch August 14, 2026 15:13
IgorOffline pushed a commit to IgorOffline/Shopify-hydrogen that referenced this pull request Oct 10, 2026
Adds support for attributes support in our cart handlers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants