Fix: Dispatch change event when updating variant ID input#54
Open
tobiasdalhof wants to merge 1 commit intoShopify:mainfrom
Open
Fix: Dispatch change event when updating variant ID input#54tobiasdalhof wants to merge 1 commit intoShopify:mainfrom
tobiasdalhof wants to merge 1 commit intoShopify:mainfrom
Conversation
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.
Problem
The variant ID is updated programmatically, which does not trigger native
inputorchangeevents. Although this input is hidden, it is the requiredname="id"field for the Shopify Add to Cart form.Many Shopify apps use this specific input as their primary source of truth because it is the most reliable way to identify the selected variant across different themes. Because the field remains "silent" during scripted updates, these apps cannot detect variant changes, causing their state or widgets to fall out of sync with the product page.
Solution
Manually dispatch a
changeevent with{ bubbles: true }immediately after the value is updated. This ensures the event propagates up the DOM, allowing both the theme and third-party apps to respond correctly.I am aware the README states that PRs are not currently accepted. I am submitting this as a reference to address a widespread compatibility issue. I hope this can be considered for a future internal update to improve the theme's interoperability.