You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Square Gift Card field renders twice on the classic checkout when the checkout updates while the field is loading #581
On the classic (shortcode) checkout, the Square Gift Card field can render twice. The second box has no "Apply" button, so shoppers see a stray input they can't use. It happens when a single extra update_checkout fires while the page loads. Delivery-date plugins do this, for example.
This is the same timing problem as the duplicate credit card field in SQUARE-355 (PR #571). That PR guards only the credit card form and doesn't touch the gift card code, so the gift card box still duplicates on its branch.
Steps to reproduce
Use a store with Square enabled and a classic checkout page (/old-checkout/ on my test site).
Add this snippet as an mu-plugin. It does nothing unless the URL has ?ted_mode=onupdate:
1, with a single "Have a Square Gift Card?" box and its Apply button.
Actual
2. Two gift card boxes are visible, and the second has no Apply button.
Results
URL
Gift card iframes
/old-checkout/ (no flag)
1
/old-checkout/?ted_mode=onupdate, trunk (56e0f0770), 3 of 3 runs
2
Same URL on the SQUARE-355 branch (05060d835)
2
Likely cause
src/js/frontend/wc-square-gift-card.js runs init() on every updated_checkout (line 39). init() awaits initializeGiftCard(), which awaits payments.giftCard() and then giftCard.attach(...) (lines 68 and 166-175). Nothing records that a build is already in progress, so a second updated_checkout during that await starts another build and mounts a second gift card into the same wrapper. init() also registers a new update_checkout listener each time it runs. The remove flow (onRemoveGiftCard, line 278) rebuilds the card in a similar way.
PR #571 fixes the credit card form with a "build in progress" flag and a queued refresh. The gift card form could use the same approach.
Environment
Chrome 156 on macOS, Square sandbox
Square for WooCommerce 5.5.2, WooCommerce 11.1.1, WordPress 7.1.4
Activity