@@ -168,6 +168,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
168168 setQtState ( ( prev ) => ( { ...prev , ...evalFunc ( null , state , prev ) } ) ) ;
169169 } ;
170170 const isDirtyRef = useRef ( false ) ; // usefull when conn change.
171+ const qtStateRef = useRef ( qtState ) ;
171172 const eventBus = useRef ( eventBusObj || ( new EventBus ( ) ) ) ;
172173 const docker = useRef ( null ) ;
173174 const api = useMemo ( ( ) => getApiInstance ( ) , [ ] ) ;
@@ -477,7 +478,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
477478 } , 100 ) ) ;
478479
479480 /* If the tab or window is not visible, applicable for open in new tab */
480- document . addEventListener ( 'visibilitychange' , function ( ) {
481+ const onVisibilityChange = function ( ) {
481482 if ( document . hidden ) {
482483 setQtStatePartial ( { is_visible : false } ) ;
483484 } else {
@@ -487,14 +488,18 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
487488 // status. This ensures a dead connection is detected right away
488489 // instead of waiting for the next poll interval, which was disabled
489490 // while the tab was hidden.
490- if ( qtState . params ?. trans_id && qtState . connected_once ) {
491- fetchConnectionStatus ( api , qtState . params . trans_id )
491+ const { params, connected_once} = qtStateRef . current ;
492+ if ( params ?. trans_id && connected_once ) {
493+ fetchConnectionStatus ( api , params . trans_id )
492494 . then ( ( { data : respData } ) => {
493495 if ( respData . data ) {
494496 setQtStatePartial ( {
495497 connected : true ,
496498 connection_status : respData . data . status ,
497499 } ) ;
500+ if ( respData . data . notifies ) {
501+ eventBus . current . fireEvent ( QUERY_TOOL_EVENTS . PUSH_NOTICE , respData . data . notifies ) ;
502+ }
498503 } else {
499504 setQtStatePartial ( {
500505 connected : false ,
@@ -513,9 +518,13 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
513518 } ) ;
514519 }
515520 }
516- } ) ;
521+ } ;
522+ document . addEventListener ( 'visibilitychange' , onVisibilityChange ) ;
523+ return ( ) => document . removeEventListener ( 'visibilitychange' , onVisibilityChange ) ;
517524 } , [ ] ) ;
518525
526+ useEffect ( ( ) => { qtStateRef . current = qtState ; } , [ qtState ] ) ;
527+
519528 useEffect ( ( ) => usePreferences . subscribe (
520529 state => {
521530 setQtStatePartial ( { preferences : {
0 commit comments