Skip to content

Include selectedOptions in add-to-cart event detail#3854

Open
AboodFares wants to merge 1 commit into
Shopify:fb-update-preview-2026-06-17from
AboodFares:fix/optimistic-cart-selected-options
Open

Include selectedOptions in add-to-cart event detail#3854
AboodFares wants to merge 1 commit into
Shopify:fb-update-preview-2026-06-17from
AboodFares:fix/optimistic-cart-selected-options

Conversation

@AboodFares

Copy link
Copy Markdown

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

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

buildAddToCartDetail omitted the selected variant's selectedOptions from
the product payload, even though it is already tracked in the product
form's observable state. Because the cart store spreads this payload into
the optimistic line's merchandise, optimistic lines had no selectedOptions
to render during the mutation window.

Cart line components that render option names (e.g. "Size: Large") could
only fall back to the variant title (e.g. "Large / Square"), producing a
visible label flicker when the mutation resolved. Adding selectedOptions
closes the gap with no consumer-side change, since CartLineMerchandise
already supports the field.

Fixes Shopify#3853
@AboodFares
AboodFares requested a review from a team as a code owner July 11, 2026 15:27
@AboodFares

Copy link
Copy Markdown
Author

I have signed the CLA!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant