diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlAdapterPreprocessor.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlAdapterPreprocessor.ts index db33a0541d..50395dc9dc 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlAdapterPreprocessor.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlAdapterPreprocessor.ts @@ -38,17 +38,20 @@ export const addControlAdapterPreprocessor = (startAppListening: AppStartListeni .find((l) => l.id === layerId); // Conditions to bail + const layerDoesNotExist = !precheckLayer; + const layerHasNoImage = !precheckLayer?.controlAdapter.image; + const layerHasNoProcessorConfig = !precheckLayer?.controlAdapter.processorConfig; + const layerIsAlreadyProcessingImage = precheckLayer?.controlAdapter.isProcessingImage; + const areImageAndProcessorUnchanged = + isEqual(precheckLayer?.controlAdapter.image, precheckLayerOriginal?.controlAdapter.image) && + isEqual(precheckLayer?.controlAdapter.processorConfig, precheckLayerOriginal?.controlAdapter.processorConfig); + if ( - // Layer doesn't exist - !precheckLayer || - // Layer doesn't have an image - !precheckLayer.controlAdapter.image || - // Layer doesn't have a processor config - !precheckLayer.controlAdapter.processorConfig || - // Layer is already processing an image - precheckLayer.controlAdapter.isProcessingImage || - // Processor config is the same - isEqual(precheckLayerOriginal?.controlAdapter.processorConfig, precheckLayer.controlAdapter.processorConfig) + layerDoesNotExist || + layerHasNoImage || + layerHasNoProcessorConfig || + areImageAndProcessorUnchanged || + layerIsAlreadyProcessingImage ) { return; } diff --git a/invokeai/frontend/web/src/features/controlLayers/store/controlLayersSlice.ts b/invokeai/frontend/web/src/features/controlLayers/store/controlLayersSlice.ts index fa179a3bbd..d4c43fdc89 100644 --- a/invokeai/frontend/web/src/features/controlLayers/store/controlLayersSlice.ts +++ b/invokeai/frontend/web/src/features/controlLayers/store/controlLayersSlice.ts @@ -250,8 +250,17 @@ export const controlLayersSlice = createSlice({ layer.bbox = null; layer.bboxNeedsUpdate = true; layer.isEnabled = true; - layer.controlAdapter.image = imageDTO ? imageDTOToImageWithDims(imageDTO) : null; - layer.controlAdapter.processedImage = null; + if (imageDTO) { + const newImage = imageDTOToImageWithDims(imageDTO); + if (isEqual(newImage, layer.controlAdapter.image)) { + return; + } + layer.controlAdapter.image = newImage; + layer.controlAdapter.processedImage = null; + } else { + layer.controlAdapter.image = null; + layer.controlAdapter.processedImage = null; + } }, caLayerProcessedImageChanged: (state, action: PayloadAction<{ layerId: string; imageDTO: ImageDTO | null }>) => { const { layerId, imageDTO } = action.payload;