Skip to content

Commit 8954953

Browse files
psychedelicioushipsterusername
authored andcommitted
fix(ui): no duplicate network requests on app startup
1 parent eb2fcbe commit 8954953

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/socketio/socketConnected.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { api } from 'services/api';
44
import { receivedOpenAPISchema } from 'services/api/thunks/schema';
55
import { appSocketConnected, socketConnected } from 'services/events/actions';
66
import { startAppListening } from '../..';
7+
import { isInitializedChanged } from 'features/system/store/systemSlice';
78

89
export const addSocketConnectedEventListener = () => {
910
startAppListening({
@@ -13,15 +14,20 @@ export const addSocketConnectedEventListener = () => {
1314

1415
log.debug('Connected');
1516

16-
const { nodes, config } = getState();
17+
const { nodes, config, system } = getState();
1718

1819
const { disabledTabs } = config;
1920

2021
if (!size(nodes.nodeTemplates) && !disabledTabs.includes('nodes')) {
2122
dispatch(receivedOpenAPISchema());
2223
}
2324

24-
dispatch(api.util.resetApiState());
25+
if (system.isInitialized) {
26+
// only reset the query caches if this connect event is a *reconnect* event
27+
dispatch(api.util.resetApiState());
28+
} else {
29+
dispatch(isInitializedChanged(true));
30+
}
2531

2632
// pass along the socket event as an application action
2733
dispatch(appSocketConnected(action.payload));

invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/socketio/socketDisconnected.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { logger } from 'app/logging/logger';
2-
import { api } from 'services/api';
32
import {
43
appSocketDisconnected,
54
socketDisconnected,
@@ -13,8 +12,6 @@ export const addSocketDisconnectedEventListener = () => {
1312
const log = logger('socketio');
1413
log.debug('Disconnected');
1514

16-
dispatch(api.util.resetApiState());
17-
1815
// pass along the socket event as an application action
1916
dispatch(appSocketDisconnected(action.payload));
2017
},

invokeai/frontend/web/src/features/system/store/systemPersistDenylist.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SystemState } from './types';
22

33
export const systemPersistDenylist: (keyof SystemState)[] = [
4+
'isInitialized',
45
'isConnected',
56
'denoiseProgress',
67
'status',

invokeai/frontend/web/src/features/system/store/systemSlice.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { SystemState, LANGUAGES } from './types';
2424
import { zPydanticValidationError } from './zodSchemas';
2525

2626
export const initialSystemState: SystemState = {
27+
isInitialized: false,
2728
isConnected: false,
2829
shouldConfirmOnDelete: true,
2930
enableImageDebugging: false,
@@ -82,6 +83,9 @@ export const systemSlice = createSlice({
8283
) {
8384
state.shouldEnableInformationalPopovers = action.payload;
8485
},
86+
isInitializedChanged(state, action: PayloadAction<boolean>) {
87+
state.isInitialized = action.payload;
88+
},
8589
},
8690
extraReducers(builder) {
8791
/**
@@ -242,6 +246,7 @@ export const {
242246
shouldUseNSFWCheckerChanged,
243247
shouldUseWatermarkerChanged,
244248
setShouldEnableInformationalPopovers,
249+
isInitializedChanged,
245250
} = systemSlice.actions;
246251

247252
export default systemSlice.reducer;

invokeai/frontend/web/src/features/system/store/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type DenoiseProgress = {
2121
};
2222

2323
export interface SystemState {
24+
isInitialized: boolean;
2425
isConnected: boolean;
2526
shouldConfirmOnDelete: boolean;
2627
enableImageDebugging: boolean;

0 commit comments

Comments
 (0)