Applying changes
Checkout UI extensions can use checkout APIs to make changes, such as updating cart lines, cart metafields, order notes, and privacy consent. Apply each change only after the buyer's intent is clear and when the new value is different. When possible, apply all changes at the same time. Before calling mutation APIs, check cart instructions to confirm that the change is allowed.
Excessive changes may rate limit the extension and prevent it from applying more changes to the checkout. Rate-limited extensions can't block the buyer journey.
Excessive changes may rate limit the extension and prevent it from applying more changes to the checkout. Rate-limited extensions can't block the buyer journey.
Anchor to Debounce user-driven changesDebounce user-driven changes
Debounce API calls that respond to user input. Calling an API after every keystroke or interaction creates unnecessary work and can degrade performance.
Debouncing input changes
Anchor to Avoid changes in render loopsAvoid changes in render loops
In code that runs on every render or in response to reactive state changes, don't apply changes to checkout state without appropriate guards. If a buyer action changes extension state, then compare the new value with the last value that your extension requested before calling the API.
Avoiding render-loop changes
Anchor to React to state changes selectivelyReact to state changes selectively
When your extension reads checkout state, such as the shipping address or cart lines, apply changes only when the specific data your extension needs has changed. Don't apply a change for every state update. The following example synchronizes the country and province as one value, and the guard prevents another request when that value stays the same.
Reacting selectively to state changes
Anchor to Apply changes at the same timeApply changes at the same time
If you need to make multiple changes, then apply them in parallel with Promise.all instead of awaiting each one sequentially. This reduces the time spent applying changes, avoids delays between calls, and makes the extension less likely to trip rate limits.
Synchronize all changes that can be applied from the same buyer intent. For example, use parallel calls when a buyer action updates a cart metafield and sets an order note.
Applying changes at the same time
Anchor to Handle errors gracefullyHandle errors gracefully
Don't retry aggressively. When a change returns an error, let the buyer retry manually. Consider retrying automatically only if the failure is due to a network error.