Skip to content

Commit 9c30a41

Browse files
committed
Cancel debounced handler on cleanup, gate visibility check by active panel
1 parent af82441 commit 9c30a41

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,15 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
484484
qtPanelDocker.eventBus.registerListener(LAYOUT_EVENTS.ACTIVE, onLayoutActive);
485485

486486
/* If the tab or window is not visible, applicable for open in new tab */
487+
// Track whether this panel was active before the window was hidden,
488+
// so only the active instance refreshes on return.
489+
let wasActiveBeforeHide = false;
487490
const onVisibilityChange = function() {
488491
if(document.hidden) {
492+
wasActiveBeforeHide = qtStateRef.current.is_visible;
489493
setQtStatePartial({is_visible: false});
490494
} else {
495+
if(!wasActiveBeforeHide) return;
491496
setQtStatePartial({is_visible: true});
492497
// When the tab becomes visible again after being hidden (e.g. user
493498
// switched away on Linux Desktop), immediately check the connection
@@ -503,6 +508,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
503508
document.addEventListener('visibilitychange', onVisibilityChange);
504509
return ()=>{
505510
document.removeEventListener('visibilitychange', onVisibilityChange);
511+
onLayoutActive.cancel();
506512
if(qtPanelDocker?.eventBus) {
507513
qtPanelDocker.eventBus.deregisterListener(LAYOUT_EVENTS.CLOSING, onLayoutClosing);
508514
qtPanelDocker.eventBus.deregisterListener(LAYOUT_EVENTS.ACTIVE, onLayoutActive);

0 commit comments

Comments
 (0)