When creating a checkout from a drat order, where the customer can’t change their shipping address, and the order uses a custom shipping option, the value of selectedDeliveryOption.handleis changing on every render after applying an attribute change, leading to rate limiting issues when trying to run operations when the selected option changes. This does not seem to happen on regular checkouts. There is no other unique field to use for tracking the selected option. Is this a bug, or is there some other approach that should be used to track selected option?
Hi there,
this looks like a draft order specific issue rather than something wrong with your implementation. Custom shipping options on draft orders seem to regenerate the handle on attribute changes, which doesn’t happen on regular checkouts.
To avoid triggering your logic on every render, you can stabilize the comparison using title and price instead of the handle:
const prevOptionRef = useRef(null);
const currentOption = deliveryGroups[0]?.selectedDeliveryOption;
const stableKey = `${currentOption?.title}-${currentOption?.cost?.totalAmount?.amount}`;
useEffect(() => {
if (stableKey !== prevOptionRef.current) {
prevOptionRef.current = stableKey;
// run your operation here
}
}, [stableKey]);
Keeps the rate limiting under control until there’s a proper fix or a unique stable field available for custom shipping options on draft orders.



