re run callbacks on tab change

This commit is contained in:
paul sealock 2024-08-16 10:59:01 +12:00
parent d08a064bbb
commit 1065e6d450
2 changed files with 12 additions and 9 deletions

View File

@ -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 <div>Error getting data</div>;
}

View File

@ -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.
}
} );