diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/enqueueRequestedLinear.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/enqueueRequestedLinear.ts index 29ff4b2224..7748e35998 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/enqueueRequestedLinear.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/enqueueRequestedLinear.ts @@ -1,12 +1,11 @@ import { enqueueRequested } from 'app/store/actions'; import type { AppStartListening } from 'app/store/middleware/listenerMiddleware'; -import { $nodeManager } from 'features/controlLayers/konva/renderers/renderer'; +import { getNodeManager } from 'features/controlLayers/konva/nodeManager'; import { isImageViewerOpenChanged } from 'features/gallery/store/gallerySlice'; import { prepareLinearUIBatch } from 'features/nodes/util/graph/buildLinearBatchConfig'; import { buildGenerationTabGraph } from 'features/nodes/util/graph/generation/buildGenerationTabGraph'; import { buildGenerationTabSDXLGraph } from 'features/nodes/util/graph/generation/buildGenerationTabSDXLGraph'; import { queueApi } from 'services/api/endpoints/queue'; -import { assert } from 'tsafe'; export const addEnqueueRequestedLinear = (startAppListening: AppStartListening) => { startAppListening({ @@ -20,8 +19,7 @@ export const addEnqueueRequestedLinear = (startAppListening: AppStartListening) let graph; - const manager = $nodeManager.get(); - assert(manager, 'Konva node manager not initialized'); + const manager = getNodeManager(); console.log('generation mode', manager.util.getGenerationMode()); diff --git a/invokeai/frontend/web/src/features/controlLayers/konva/nodeManager.ts b/invokeai/frontend/web/src/features/controlLayers/konva/nodeManager.ts index f31a74b1f3..2fa562b44f 100644 --- a/invokeai/frontend/web/src/features/controlLayers/konva/nodeManager.ts +++ b/invokeai/frontend/web/src/features/controlLayers/konva/nodeManager.ts @@ -21,6 +21,7 @@ import type { import { isValidLayer } from 'features/nodes/util/graph/generation/addLayers'; import type Konva from 'konva'; import type { Vector2d } from 'konva/lib/types'; +import { atom } from 'nanostores'; import { getImageDTO as defaultGetImageDTO, uploadImage as defaultUploadImage } from 'services/api/endpoints/images'; import type { ImageCategory, ImageDTO } from 'services/api/types'; import { assert } from 'tsafe'; @@ -466,3 +467,13 @@ export class KonvaEntityAdapter { return this.objectRecords.delete(id); } } + +const $nodeManager = atom(null); +export const setNodeManager = (manager: KonvaNodeManager) => { + $nodeManager.set(manager); +}; +export const getNodeManager = () => { + const nodeManager = $nodeManager.get(); + assert(nodeManager, 'Konva node manager not initialized'); + return nodeManager; +}; diff --git a/invokeai/frontend/web/src/features/controlLayers/konva/renderers/renderer.ts b/invokeai/frontend/web/src/features/controlLayers/konva/renderers/renderer.ts index 939d9d776c..11fb09e57f 100644 --- a/invokeai/frontend/web/src/features/controlLayers/konva/renderers/renderer.ts +++ b/invokeai/frontend/web/src/features/controlLayers/konva/renderers/renderer.ts @@ -4,7 +4,7 @@ import { logger } from 'app/logging/logger'; import { $isDebugging } from 'app/store/nanostores/isDebugging'; import type { RootState } from 'app/store/store'; import { setStageEventHandlers } from 'features/controlLayers/konva/events'; -import { KonvaNodeManager } from 'features/controlLayers/konva/nodeManager'; +import { KonvaNodeManager, setNodeManager } from 'features/controlLayers/konva/nodeManager'; import { getArrangeEntities } from 'features/controlLayers/konva/renderers/arrange'; import { createBackgroundLayer, getRenderBackground } from 'features/controlLayers/konva/renderers/background'; import { updateBboxes } from 'features/controlLayers/konva/renderers/bbox'; @@ -66,12 +66,9 @@ import type { import type Konva from 'konva'; import type { IRect, Vector2d } from 'konva/lib/types'; import { debounce } from 'lodash-es'; -import { atom } from 'nanostores'; import type { RgbaColor } from 'react-colorful'; import type { ImageDTO } from 'services/api/types'; -export const $nodeManager = atom(null); - /** * Initializes the canvas renderer. It subscribes to the redux store and listens for changes directly, bypassing the * react rendering cycle entirely, improving canvas performance. @@ -301,7 +298,7 @@ export const initializeRenderer = ( }; const manager = new KonvaNodeManager(stage, container); - $nodeManager.set(manager); + setNodeManager(manager); manager.background = { layer: createBackgroundLayer() }; manager.stage.add(manager.background.layer);