@@ -164,13 +164,16 @@ export const handlePlatformCheckoutEmailInput = ( field, api ) => {
164
164
iframeWrapper . insertBefore ( iframeArrow , null ) ;
165
165
iframeWrapper . insertBefore ( iframe , null ) ;
166
166
167
- const closeIframe = ( ) => {
167
+ const closeIframe = ( focus = true ) => {
168
168
window . removeEventListener ( 'resize' , getWindowSize ) ;
169
169
window . removeEventListener ( 'resize' , setPopoverPosition ) ;
170
170
171
171
iframeWrapper . remove ( ) ;
172
172
iframe . classList . remove ( 'open' ) ;
173
- platformCheckoutEmailInput . focus ( ) ;
173
+
174
+ if ( focus ) {
175
+ platformCheckoutEmailInput . focus ( ) ;
176
+ }
174
177
175
178
document . body . style . overflow = '' ;
176
179
} ;
@@ -259,24 +262,39 @@ export const handlePlatformCheckoutEmailInput = ( field, api ) => {
259
262
260
263
// Prevent show platform checkout iframe if the page comes from
261
264
// the back button on platform checkout itself.
262
- const searchParams = new URLSearchParams ( window . location . search ) ;
265
+ window . addEventListener ( 'pageshow' , function ( event ) {
266
+ // Detect browser back button.
267
+ const historyTraversal =
268
+ event . persisted ||
269
+ ( 'undefined' !== typeof performance &&
270
+ 'back_forward' ===
271
+ performance . getEntriesByType ( 'navigation' ) [ 0 ] . type ) ;
263
272
264
- if ( 'true' !== searchParams . get ( 'skip_platform_checkout' ) ) {
265
- // Check the initial value of the email input and trigger input validation.
266
- if ( validateEmail ( platformCheckoutEmailInput . value ) ) {
267
- platformCheckoutLocateUser ( platformCheckoutEmailInput . value ) ;
268
- }
269
- } else {
270
- searchParams . delete ( 'skip_platform_checkout' ) ;
273
+ const searchParams = new URLSearchParams ( window . location . search ) ;
274
+
275
+ if (
276
+ ! historyTraversal &&
277
+ 'true' !== searchParams . get ( 'skip_platform_checkout' )
278
+ ) {
279
+ // Check the initial value of the email input and trigger input validation.
280
+ if ( validateEmail ( platformCheckoutEmailInput . value ) ) {
281
+ platformCheckoutLocateUser ( platformCheckoutEmailInput . value ) ;
282
+ }
283
+ } else {
284
+ searchParams . delete ( 'skip_platform_checkout' ) ;
271
285
272
- let { pathname } = window . location ;
286
+ let { pathname } = window . location ;
273
287
274
- if ( '' !== searchParams . toString ( ) ) {
275
- pathname += '?' + searchParams . toString ( ) ;
276
- }
288
+ if ( '' !== searchParams . toString ( ) ) {
289
+ pathname += '?' + searchParams . toString ( ) ;
290
+ }
277
291
278
- history . replaceState ( null , null , pathname ) ;
279
- }
292
+ history . replaceState ( null , null , pathname ) ;
293
+
294
+ // Safari needs to close iframe with this.
295
+ closeIframe ( false ) ;
296
+ }
297
+ } ) ;
280
298
281
299
platformCheckoutEmailInput . addEventListener ( 'input' , ( e ) => {
282
300
const email = e . currentTarget . value ;
0 commit comments