✨ Sync Host Cart on VTEX IO After WebChat Add-to-Cart#87
Open
cristiantela wants to merge 2 commits intov3-mainfrom
Open
✨ Sync Host Cart on VTEX IO After WebChat Add-to-Cart#87cristiantela wants to merge 2 commits intov3-mainfrom
cristiantela wants to merge 2 commits intov3-mainfrom
Conversation
paulobernardoaf
approved these changes
Apr 16, 2026
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.
Description
Type of Change
Motivation and Context
After a product is added through the webchat, the host storefront should reflect the new cart. FastStore exposes
faststore_sdk_storesso the cart can be refreshed with a simpleread/set. On VTEX IO storefronts that is not available, so the minicart could stay stale even though the checkout order form was updated server-side. This change adds a fallback that refreshes the VTEX IO minicart by syncing React state with the latest order form when FastStore sync is not used.Summary of Changes
src/utils/VTEXIOMinicartBridge.js: loads the current order form from/api/checkout/pub/orderForm?allowedOutdatedData=false, locates a minicart-related DOM node, walks the React fiber tree to find anOrderForm-style provider and the hook whose state includesitems[], then dispatches the fresh order form (and attempts to refresh adjacent numeric hooks used as item count). ExposesupdateVTEXIOMinicartand registerswindow.updateMinicartfor manual or external use after cart changes. Errors are handled internally so failures do not break the webchat flow.OrderFormContext: replacedtrySyncFaststoreCartwithtrySyncHostCart. It first tries FastStore’s cart store when present; if that path does not apply or throws, itawaitsupdateVTEXIOMinicart()inside a try/catch so VTEX IO sync never propagates errors to the UI.CounterControls: after a successful add-to-cart, callsvoid trySyncHostCart()so the async host sync is fire-and-forget without an unhandled promise.