mirror of
https://github.com/tinyhumansai/openhuman.git
synced 2026-07-27 21:08:00 +00:00
fix: clear stale backend errors while reconnecting (#2616)
Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
This commit is contained in:
co-authored by
Steven Enamakel
parent
3556842337
commit
695bff458e
@@ -39,6 +39,23 @@ describe('connectivitySlice', () => {
|
||||
expect(state.lastError.backend).toBeUndefined();
|
||||
});
|
||||
|
||||
it('setBackend clears the stale backend error when a reconnect begins (connecting)', () => {
|
||||
// A prior disconnect leaves an error string in state…
|
||||
let state = connectivityReducer(
|
||||
undefined,
|
||||
setBackend({ value: 'disconnected', error: 'transport close' })
|
||||
);
|
||||
expect(state.lastError.backend).toBe('transport close');
|
||||
|
||||
// …and the reconnect attempt ('connecting') must fully clear it rather than
|
||||
// leave the key present-but-undefined, so the UI does not surface a stale
|
||||
// disconnect message during the reconnection window.
|
||||
state = connectivityReducer(state, setBackend({ value: 'connecting' }));
|
||||
expect(state.backend).toBe('connecting');
|
||||
expect(state.lastError.backend).toBeUndefined();
|
||||
expect('backend' in state.lastError).toBe(false);
|
||||
});
|
||||
|
||||
it('initial internet state is "offline" when navigator.onLine is false (line 33)', () => {
|
||||
// Simulate the browser reporting no network at boot time.
|
||||
const originalOnLine = Object.getOwnPropertyDescriptor(navigator, 'onLine');
|
||||
|
||||
@@ -58,7 +58,13 @@ const slice = createSlice({
|
||||
},
|
||||
setBackend(state, action: PayloadAction<{ value: BackendState; error?: string }>) {
|
||||
state.backend = action.payload.value;
|
||||
if (action.payload.value === 'connected') {
|
||||
if (action.payload.value === 'connected' || action.payload.value === 'connecting') {
|
||||
// Clear the stale error on both successful connection and reconnect
|
||||
// attempts. Previously only 'connected' deleted lastError.backend,
|
||||
// which meant a prior disconnect error (e.g. "transport close") was
|
||||
// left set to `undefined` — not deleted — during 'connecting'. UI
|
||||
// components that read lastError.backend could still surface a stale
|
||||
// message in the reconnect window even though the key appeared falsy.
|
||||
delete state.lastError.backend;
|
||||
} else {
|
||||
state.lastError.backend = action.payload.error;
|
||||
|
||||
Reference in New Issue
Block a user