Repository navigation
SQUARE-355: Duplicate credit card field rendered on checkout in Chrome (classic checkout) - #571
Conversation
…ds while the form is building
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
There was a problem hiding this comment.
🔵 Needs a closer look
Payment-lifecycle timing changes need deterministic regression coverage and human review of cleanup serialization and compatibility.
2 open issues
What changed in this PR
Prevents duplicate Square card fields during overlapping classic-checkout updates. Block checkout remains unchanged.
Changes:
- Serializes card setup and teardown, queuing overlapping refreshes.
- Improves failed-build cleanup and stale-container handling.
- Handles submission before the card field is ready.
| File | Description |
|---|---|
| src/js/frontend/wc-square.js | Adds lifecycle guards, queued refreshes, cleanup, and payment-readiness checks. |
Review effort: Balanced
iamdharmesh
left a comment
There was a problem hiding this comment.
Thanks for the PR @faisal-alvi. This looks great overall. Could you please check on 2 feedback added by Copilot? once those addressed this will be ready for the next steps.
…d form lifecycle e2e tests
|
@iamdharmesh Thanks. I've addressed both Copilot comments:
I also made the fix smaller. I dropped the extra Place order check, since Tested locally: |
QA Update: Test Pass
Steps ✅ Steps 3–4: the duplicate card reproduces on trunk and is gone on the branch. @faisal-alvi @iamdharmesh Finding outside this PR’s scope: the Square Gift Card field also renders twice under the same trigger.
🖥 Testing Environment Details
|
Regression / Smoke Test Report ✅Tested with Archive File created via "php woorelease.phar build repo_URL" (Composer version 2.8.4, npm version 10.8.2, node version 20.18.1) Status- Working expected with Plugin Archive/Zip file same as fix specific branch. Testing Environment Details
🔁 Next Step- Ready to Merge 🚀 |


All Submissions:
Changes proposed in this Pull Request:
On the classic (shortcode) checkout, the Square credit card field can render twice. Shoppers then don't know which field to use, and the merchant who reported it has lost orders because of it. Despite the ticket title, this isn't specific to Chrome. It's a timing issue: any plugin that triggers a single
update_checkoutwhile the page loads can cause it, delivery-date pickers for example.The card form is only recorded as "built" after Square's async card setup finishes. If another checkout update arrives during that window, the existing guard doesn't see a form yet, so it starts a second build, and both cards mount into the same container. A checkout update that lands while an existing form is being torn down can double-build the same way.
This PR makes the card form lifecycle safe against overlapping updates:
a94.credit-card-form-lifecycle.spec.js) cover a checkout update while the card is loading, and clicking Place order before the card is ready, then retrying.Block checkout is not affected (it uses a separate code path).
Closes https://linear.app/a8c/issue/SQUARE-355/duplicate-credit-card-field-rendered-on-checkout-in-chrome-classic
Steps to test the changes in this Pull Request:
?ted_mode=onupdate, and then fires oneupdate_checkoutfrom inside the firstupdated_checkout, like the delivery-date plugins do:trunk, add a product to the cart and open the checkout with?ted_mode=onupdate. Select the Square credit card method and rundocument.querySelectorAll('#wc-square-credit-card-container iframe.sq-card-component').lengthin the console. It returns2and two card fields are visible. Note that the race depends on the server answering the checkout update faster than Square builds the card. On a slow local site it may not show, in which case delay Square's requests (e.g. a Playwrightroutethat holdssquarecdn.com/squareupsandbox.comrequests for ~1.5s).1, with a single card field, every time.4111 1111 1111 1111. The order should be placed with no errors.?ted_mode=onupdate, select Square, and click Place order straight away, before the card field has appeared. A general payment error is shown, the form is not left blocked, and there are no console errors. Fill the card in and place the order. It succeeds.Changelog entry