Fix connection banner not disappearing (#9532)

* Fix connection banner not disappearing

* Add relevant test
This commit is contained in:
Daniel Espino García 2026-03-03 13:08:45 +01:00 committed by GitHub
parent c313f7712f
commit 1a01c532a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View file

@ -346,6 +346,31 @@ describe('useConnectionBanner', () => {
});
});
it('should not re-show banner the moment it closes (effect omits visible from deps)', () => {
jest.useFakeTimers();
const {result} = renderHook(() => useConnectionBanner({
websocketState: 'connected' as WebsocketConnectedState,
networkPerformanceState: 'normal' as NetworkPerformanceState,
netInfo: createMockNetInfo(false),
appState: 'active',
intl: mockIntl,
}));
expect(result.current.visible).toBe(true);
expect(result.current.bannerText).toBe('The server is not reachable');
// Auto-close: the hook sets a 2s timeout when showing internet unreachable. Advance
// time so closeCallback runs. visible becomes false; netInfo is still unreachable.
act(() => {
jest.advanceTimersByTime(2100);
});
expect(result.current.visible).toBe(false);
jest.useRealTimers();
});
it('should not show other banners when one is already visible with timeout', async () => {
const {result, rerender} = renderHook(
(props) => useConnectionBanner(props),

View file

@ -162,13 +162,16 @@ export const useConnectionBanner = ({
};
priorities();
// We omit 'visible' from dependencies because we do not want
// to show again the banner the moment the banner is closed.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
handleInternetUnreachableState,
handleDisconnectedState,
handleSlowNetworkState,
handleConnectedState,
handleConnectingState,
visible,
appState,
]);