diff --git a/plugins/woocommerce-admin/client/settings/index.js b/plugins/woocommerce-admin/client/settings/index.js index 15bfdf5e877..efa3d2e7007 100644 --- a/plugins/woocommerce-admin/client/settings/index.js +++ b/plugins/woocommerce-admin/client/settings/index.js @@ -44,6 +44,9 @@ const Settings = ( { params } ) => { setSidebarContent, sidebarVisisble ); + + const event = new Event( 'reactRendered' ); + window.dispatchEvent( event ); }, [ params.page, section, sidebarVisisble ] ); // Register the slot fills for the settings page just once. @@ -58,11 +61,6 @@ const Settings = ( { params } ) => { setSidebarVisisble( false ); }, [ params.page, section ] ); - useEffect( () => { - const event = new Event( 'reactRendered' ); - window.dispatchEvent( event ); - }, [] ); - if ( ! settingsData ) { return
Error getting data
; } diff --git a/plugins/woocommerce/client/legacy/js/admin/jquery-in-react.js b/plugins/woocommerce/client/legacy/js/admin/jquery-in-react.js index db9304b0015..601966101e9 100644 --- a/plugins/woocommerce/client/legacy/js/admin/jquery-in-react.js +++ b/plugins/woocommerce/client/legacy/js/admin/jquery-in-react.js @@ -12,12 +12,17 @@ function releaseReady() { // Restore the original jQuery.fn.ready method jQuery.fn.ready = originalReady; - // Execute all queued callbacks - while ( callbacks.length ) { - callbacks.shift()( jQuery ); + // Execute all queued callbacks but save them for when switching tabs. + const callbacksCopy = [ ...callbacks ]; + while ( callbacksCopy.length ) { + callbacksCopy.shift()( jQuery ); } } jQuery( window ).on( 'reactRendered', function () { - releaseReady(); + try { + releaseReady(); + } catch ( error ) { + // swallow errors here - I'm sorry. + } } );