Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(webv2): finish the live-refresh hover fix, and stop refetching on editor entry

Lincoln Steinee4fabd6f44c
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapDataRuntime.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapDataRuntime.test.ts
index f97a889a55..65f9fe7fba 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapDataRuntime.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapDataRuntime.test.ts
@@ -173,6 +173,10 @@ describe('attachImageMapDataRuntime', () => {
const onConnection = mocks.onConnectionChange.mock.calls[0][0];
imageMapStore.patchSnapshot({ loadState: 'error' });
+ // The subscribe-time replay establishes the baseline, nothing more.
+ onConnection('disconnected');
+ expect(mocks.refreshImageMapPoints).not.toHaveBeenCalled();
+
onConnection('connected');
expect(mocks.refreshImageMapPoints).toHaveBeenCalledTimes(1);
onConnection('disconnected');
@@ -182,4 +186,24 @@ describe('attachImageMapDataRuntime', () => {
expect(detachSocket).toHaveBeenCalledTimes(3);
expect(detachConnection).toHaveBeenCalledTimes(1);
});
+
+ it('does not refetch when it attaches to an already-connected socket', () => {
+ imageMapStore.patchSnapshot({ loadState: 'loaded' });
+
+ // `onConnectionChange` replays the current status synchronously, and every
+ // Launchpad -> Editor navigation remounts this runtime; treating that
+ // replay as a reconnect refetched the whole point set on each entry.
+ const detach = attachImageMapDataRuntime();
+ const onConnection = mocks.onConnectionChange.mock.calls[0][0];
+
+ onConnection('connected');
+ expect(mocks.refreshImageMapPoints).not.toHaveBeenCalled();
+
+ // A genuine drop and recovery still refreshes.
+ onConnection('disconnected');
+ onConnection('connected');
+ expect(mocks.refreshImageMapPoints).toHaveBeenCalledTimes(1);
+
+ detach();
+ });
});
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapDataRuntime.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapDataRuntime.tsx
index bb408f14bf..52070b95ac 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapDataRuntime.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapDataRuntime.tsx
@@ -88,8 +88,19 @@ export const attachImageMapDataRuntime = (): (() => void) => {
}
}),
];
+ // `onConnectionChange` replays the current status synchronously on subscribe,
+ // and this runtime is remounted by every Launchpad -> Editor navigation. That
+ // replay only establishes the baseline: an already-connected socket has
+ // missed nothing, and refetching on it costs a full point set on every entry
+ // into the editor. Only a real disconnected -> connected transition can have
+ // gaps to close.
+ let previousStatus: string | null = null;
const detachConnection = socketHub.onConnectionChange((status) => {
- if (status === 'connected') {
+ const isReconnect = previousStatus !== null && previousStatus !== 'connected' && status === 'connected';
+
+ previousStatus = status;
+
+ if (isReconnect) {
refreshIfLoaded();
}
});
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsx
index 3c85eafc2f..734a059dbd 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsx
@@ -220,7 +220,12 @@ const ImageMapPlot = () => {
const { clientX, clientY } = mouse;
hoverTimerRef.current = setTimeout(() => {
void getThumbnailUrl(imageName).then((url) => {
- if (url && hoverSessionRef.current === session && !disposed) {
+ // Deliberately not gated on `disposed`: that belongs to this
+ // effect, which re-runs on every socket-driven refresh, so a
+ // refresh landing mid-dwell would drop the thumbnail — and no
+ // new `plotly_hover` fires while the pointer sits still.
+ // Unmount is covered by the session bump in the cleanup below.
+ if (url && hoverSessionRef.current === session) {
setHoverPreview({ clientX, clientY, imageName, url });
}
});
@@ -256,6 +261,10 @@ const ImageMapPlot = () => {
// this, but it reruns on every `points` change.
useEffect(() => clearHover, []);
+ // Ending the session retires the hover for good. Hiding it alone is not
+ // enough: an image that leaves the map never fires `plotly_unhover`, so a
+ // later refresh restoring it would pop the thumbnail back up at coordinates
+ // captured long before, wherever the pointer has since moved.
// Live gold target on the currently selected gallery image, with a gentle
// recenter (zoom width preserved) when it drifts near or beyond an edge.
useEffect(() => {
@@ -376,11 +385,11 @@ const ImageMapPlot = () => {
}, []);
// A live refresh can drop the hovered image from the map, which makes the
- // preview stale. Derived rather than cleared from an effect: `points`
- // changes on every socket-driven refresh, so clearing on that dependency
- // would silently cancel hovers on a busy server — and they would not come
- // back, since `Plotly.react` resets hover state and no new `plotly_hover`
- // fires until the pointer moves.
+ // preview stale. Derived from whether the image is still on the map, not
+ // from `points` changing: that changes on every socket-driven refresh, and
+ // clearing on it would silently cancel live hovers — they would not come
+ // back either, since `Plotly.react` resets hover state and no new
+ // `plotly_hover` fires until the pointer moves.
const hoverPreview =
pendingHoverPreview && points && !points.some((point) => point.imageName === pendingHoverPreview.imageName)
? null
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetFooter.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetFooter.tsx
index 8e582dd30f..8aa4fb56de 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetFooter.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetFooter.tsx
@@ -17,7 +17,11 @@ const handleRefresh = () => {
export const ImageMapWidgetFooter = (_props: WidgetViewProps) => {
const { data, indexCounts, loadState } = imageMapStore.useSnapshot();
- if (loadState === 'idle' || !data) {
+ // Only the states that actually show a map. `disabled`, `model_missing` and
+ // `empty` all carry data too, and each renders its own explanation — a
+ // "0 points" line with a Refresh button under "Image indexing is off" says
+ // nothing, and `computing` already offers its own "Check again".
+ if (loadState === 'idle' || !data || data.state !== 'ready') {
return null;
}