Skip to content

Commit 0a6b0a5

Browse files
authored
[ECP-9954] Fix intermittent Google Pay button not rendering on checkout load (#3321)
* [ECP-9954] Fix intermittent Google Pay button not rendering on checkout load * chore: trigger CI
1 parent 8a258fa commit 0a6b0a5

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

view/frontend/web/js/view/payment/method-renderer/adyen-pm-method.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,39 @@ define(
7878
self.enablePaymentMethod(paymentMethodsObserver());
7979
}
8080

81-
this._lastGrandTotal = undefined;
81+
// Seed the baseline from the current total so the first totals emission doesn't trigger
82+
// a rebuild that races with the initial mount and can leave wallet buttons unrendered.
83+
// A missing/null total is treated as "no baseline yet", consistent with the guard below.
84+
const initialTotals = quote.totals();
85+
this._lastGrandTotal = (initialTotals && initialTotals.grand_total !== null) ? initialTotals.grand_total : undefined;
8286

8387
// This event is triggered when the total changes or billing address is added (virtual products)
8488
quote.totals.subscribe(function (totals) {
8589
if (!totals) {
8690
return;
8791
}
8892
const newGrandTotal = totals.grand_total;
89-
if (Number(newGrandTotal) !== Number(self._lastGrandTotal)) {
90-
self._lastGrandTotal = newGrandTotal;
93+
// Ignore emissions without a usable total so a transient empty/cleared totals
94+
// object can't corrupt the baseline and suppress a later legitimate rebuild.
95+
if (newGrandTotal === undefined || newGrandTotal === null) {
96+
return;
97+
}
98+
const previousGrandTotal = self._lastGrandTotal;
9199

92-
// Rebuild component with updated configuration
93-
if (self.isChecked() === self.getCode()) {
94-
self.rebuildComponentAfterAmountChange();
95-
}
100+
if (Number(newGrandTotal) === Number(previousGrandTotal)) {
101+
return;
102+
}
103+
104+
self._lastGrandTotal = newGrandTotal;
105+
106+
// Establish the baseline on the first total without rebuilding.
107+
if (typeof previousGrandTotal === 'undefined') {
108+
return;
109+
}
110+
111+
// Rebuild component with updated configuration
112+
if (self.isChecked() === self.getCode()) {
113+
self.rebuildComponentAfterAmountChange();
96114
}
97115
});
98116

0 commit comments

Comments
 (0)