hydrogen icon indicating copy to clipboard operation
hydrogen copied to clipboard

Include selectedOptions in add-to-cart event detail

Open AboodFares opened this issue 4 months ago • 1 comments

WHY are these changes introduced?

Fixes #3853

buildAddToCartDetail doesn't include the variant's selectedOptions when it builds the add-to-cart detail, even though it's already available on the selected variant. The cart store spreads that payload into the optimistic line's merchandise, so the optimistic line ends up with no selectedOptions.

The effect is a flicker: cart lines that show option names like Size: Large have nothing to render during the optimistic window and fall back to the variant title (Large / Square), then snap to the real options once the mutation resolves.

WHAT is this pull request doing?

Adding selectedOptions to the product payload in buildAddToCartDetail. Nothing else needs to change since the cart store already spreads the whole payload into merchandise and CartLineMerchandise already has the field. Also updated the existing tests and added one that checks the optimistic detail includes selectedOptions.

HOW to test your changes?

vitest run src/core/product/product-form.test.ts

All passing.

Checklist

  • [x] I've read the Contributing Guidelines
  • [ ] I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • [x] I've added a changeset if this PR contains user-facing or functional changes.
  • [x] I've added tests to cover my changes
  • [ ] I've added or updated the documentation

AboodFares avatar Jul 11 '26 15:07 AboodFares

I have signed the CLA!

AboodFares avatar Jul 11 '26 15:07 AboodFares