Skip to content

Commit 2e3adcd

Browse files
authored
Prevent multiple save appearance AJAX calls on Block Checkout (#4506)
* Fix multiple save appearance AJAX calls - Update global appearance data immediately after generation to prevent subsequent calls from seeing empty data - Add concurrency flag to prevent multiple simultaneous save appearance requests * Add changelog entries
1 parent ea2a035 commit 2e3adcd

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Tweak - Use wp_ajax prefix for its built-in security for Add Payment Method action
1212
* Dev - Fix WooCommerce version fetching in GitHub workflows
1313
* Dev - Fix failing test cases associated with WooCommerce 10.0.x
14+
* Fix - Prevent multiple save appearance AJAX calls on Block Checkout
1415
* Fix - Fix required field error message and PHP warning for custom checkout fields that don't have a label
1516

1617
= 9.7.0 - 2025-07-21 =

client/stripe-utils/utils.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,10 @@ export const showErrorPaymentMethod = ( errorMessage, containerSelector ) => {
613613
*
614614
* @return {Object} The appearance object for the UPE.
615615
*/
616+
617+
// Track if save appearance is already in progress to prevent multiple calls
618+
let isSavingAppearance = false;
619+
616620
export const initializeUPEAppearance = ( api, isBlockCheckout = 'false' ) => {
617621
let appearance =
618622
isBlockCheckout === 'true'
@@ -631,8 +635,21 @@ export const initializeUPEAppearance = ( api, isBlockCheckout = 'false' ) => {
631635
! data.isChangingPayment );
632636

633637
// If we have re-built the appearance, only update the settings in the checkout context
634-
if ( isValidUpdateContext ) {
635-
api.saveAppearance( appearance, isBlockCheckout );
638+
if ( isValidUpdateContext && ! isSavingAppearance ) {
639+
// Set flag to prevent concurrent saves
640+
isSavingAppearance = true;
641+
642+
// Update the global variable immediately to prevent multiple AJAX calls
643+
if ( isBlockCheckout === 'true' ) {
644+
data.blocksAppearance = appearance;
645+
} else {
646+
data.appearance = appearance;
647+
}
648+
649+
api.saveAppearance( appearance, isBlockCheckout ).finally( () => {
650+
// Reset flag when save completes (success or failure)
651+
isSavingAppearance = false;
652+
} );
636653
}
637654
}
638655

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
121121
* Tweak - Use wp_ajax prefix for its built-in security for Add Payment Method action
122122
* Dev - Fix WooCommerce version fetching in GitHub workflows
123123
* Dev - Fix failing test cases associated with WooCommerce 10.0.x
124+
* Fix - Prevent multiple save appearance AJAX calls on Block Checkout
124125
* Fix - Fix required field error message and PHP warning for custom checkout fields that don't have a label
125126

126127
[See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)