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): keep viewport and scroll across switches

joshistoastece60deb3c87
diff --git a/invokeai/frontend/webv2/performance/architecture-baseline.json b/invokeai/frontend/webv2/performance/architecture-baseline.json
index 587e7496f9..581cace670 100644
--- a/invokeai/frontend/webv2/performance/architecture-baseline.json
+++ b/invokeai/frontend/webv2/performance/architecture-baseline.json
@@ -2,12 +2,12 @@
"build": {
"launchpad": {
"baseline": {
- "brotliBytes": 832861,
+ "brotliBytes": 833020,
"cssRawBytes": 2159,
"fontRawBytes": 219480,
- "gzipBytes": 832758,
+ "gzipBytes": 832899,
"imageRawBytes": 156376,
- "initialRawBytes": 1935956,
+ "initialRawBytes": 1936327,
"largestAssetRawBytes": 746305,
"otherAssetRawBytes": 0,
"ownedRawBytes": 67300,
@@ -177,6 +177,7 @@
"source:src/platform/pwa/registerServiceWorker.ts",
"source:src/platform/query/client.ts",
"source:src/platform/react/useMountEffect.ts",
+ "source:src/platform/react/usePreservedScrollOffset.ts",
"source:src/platform/react/useZodForm.ts",
"source:src/platform/search/dateTokens.ts",
"source:src/platform/state/accountLifecycle.ts",
@@ -281,12 +282,12 @@
]
},
"limits": {
- "brotliBytes": 841190,
+ "brotliBytes": 841351,
"cssRawBytes": 2181,
"fontRawBytes": 221675,
- "gzipBytes": 841086,
+ "gzipBytes": 841228,
"imageRawBytes": 157940,
- "initialRawBytes": 1955316,
+ "initialRawBytes": 1955691,
"largestAssetRawBytes": 753769,
"otherAssetRawBytes": 0,
"ownedRawBytes": 67300,
@@ -299,12 +300,12 @@
},
"editor": {
"baseline": {
- "brotliBytes": 1034065,
+ "brotliBytes": 1034219,
"cssRawBytes": 2159,
"fontRawBytes": 219480,
- "gzipBytes": 1031559,
+ "gzipBytes": 1031683,
"imageRawBytes": 156376,
- "initialRawBytes": 2538750,
+ "initialRawBytes": 2539121,
"largestAssetRawBytes": 746305,
"otherAssetRawBytes": 0,
"ownedRawBytes": 112650,
@@ -607,6 +608,7 @@
"source:src/platform/react/composeProviders.tsx",
"source:src/platform/react/draftRegistry.ts",
"source:src/platform/react/useMountEffect.ts",
+ "source:src/platform/react/usePreservedScrollOffset.ts",
"source:src/platform/react/useZodForm.ts",
"source:src/platform/search/dateTokens.ts",
"source:src/platform/state/accountLifecycle.ts",
@@ -840,12 +842,12 @@
]
},
"limits": {
- "brotliBytes": 1044406,
+ "brotliBytes": 1044562,
"cssRawBytes": 2181,
"fontRawBytes": 221675,
- "gzipBytes": 1041875,
+ "gzipBytes": 1042000,
"imageRawBytes": 157940,
- "initialRawBytes": 2564138,
+ "initialRawBytes": 2564513,
"largestAssetRawBytes": 753769,
"otherAssetRawBytes": 0,
"ownedRawBytes": 112650,
@@ -902,9 +904,7 @@
"src/features/queue/ui/launchpad/QueueStatusBand.tsx",
"src/workbench/launchpad/home/livePanels.ts"
],
- "editorForbiddenInitialChunkNames": [
- "ag-psd"
- ],
+ "editorForbiddenInitialChunkNames": ["ag-psd"],
"inactiveWidgetGateOwner": "deepen-widget-registry-loading"
}
}
diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.json
index 42502956d0..5f5f5dc6e4 100644
--- a/invokeai/frontend/webv2/performance/browser-baseline.json
+++ b/invokeai/frontend/webv2/performance/browser-baseline.json
@@ -25,13 +25,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 113.5,
+ "domContentLoadedMedianMs": 110,
"id": "launchpad",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 113.60000000149012,
- "longestTaskMaxMs": 70,
+ "loadMedianMs": 110.19999999925494,
+ "longestTaskMaxMs": 67,
"owner": "app",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:launchpad",
@@ -43,9 +43,9 @@
"largestAssetRawBytes": 746305,
"otherRawBytes": 136426,
"requestCount": 36,
- "scriptRawBytes": 1610114,
+ "scriptRawBytes": 1610485,
"scriptRequestCount": 32,
- "totalRawBytes": 1772363
+ "totalRawBytes": 1772734
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -54,11 +54,11 @@
"largestAssetRawBytes": 753769,
"otherRawBytes": 137791,
"requestCount": 36,
- "scriptRawBytes": 1626216,
+ "scriptRawBytes": 1626590,
"scriptRequestCount": 32,
- "totalRawBytes": 1790087
+ "totalRawBytes": 1790462
},
- "routeReadyMedianMs": 251.90000000223517,
+ "routeReadyMedianMs": 248.29999999701977,
"scriptSourceOwnerSet": "launchpad-static",
"stateProfile": "empty"
},
@@ -85,12 +85,12 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 113.5,
+ "domContentLoadedMedianMs": 111.69999999925494,
"id": "launchpad",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 113.60000000149012,
+ "loadMedianMs": 111.89999999850988,
"longestTaskMaxMs": 68,
"owner": "app",
"projectSwitchMedianMs": 0,
@@ -103,9 +103,9 @@
"largestAssetRawBytes": 746305,
"otherRawBytes": 136426,
"requestCount": 36,
- "scriptRawBytes": 1610114,
+ "scriptRawBytes": 1610485,
"scriptRequestCount": 32,
- "totalRawBytes": 1772363
+ "totalRawBytes": 1772734
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -114,11 +114,11 @@
"largestAssetRawBytes": 753769,
"otherRawBytes": 137791,
"requestCount": 36,
- "scriptRawBytes": 1626216,
+ "scriptRawBytes": 1626590,
"scriptRequestCount": 32,
- "totalRawBytes": 1790087
+ "totalRawBytes": 1790462
},
- "routeReadyMedianMs": 264.6000000014901,
+ "routeReadyMedianMs": 264.8999999985099,
"scriptSourceOwnerSet": "launchpad-static",
"stateProfile": "representative"
},
@@ -145,15 +145,15 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 114.10000000149012,
+ "domContentLoadedMedianMs": 117.90000000223517,
"id": "editor-minimal",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 114.30000000074506,
- "longestTaskMaxMs": 93,
+ "loadMedianMs": 118,
+ "longestTaskMaxMs": 86,
"owner": "workbench",
- "projectSwitchMedianMs": 34.599999997764826,
+ "projectSwitchMedianMs": 36.30000000074506,
"readyMark": "invokeai:ready:widget:center:preview",
"remediationTicket": "deepen-widget-registry-loading",
"resourceBaseline": {
@@ -163,9 +163,9 @@
"largestAssetRawBytes": 746305,
"otherRawBytes": 136426,
"requestCount": 109,
- "scriptRawBytes": 3048378,
+ "scriptRawBytes": 3048854,
"scriptRequestCount": 104,
- "totalRawBytes": 3367003
+ "totalRawBytes": 3367479
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -174,11 +174,11 @@
"largestAssetRawBytes": 753769,
"otherRawBytes": 137791,
"requestCount": 109,
- "scriptRawBytes": 3078862,
+ "scriptRawBytes": 3079343,
"scriptRequestCount": 104,
- "totalRawBytes": 3400674
+ "totalRawBytes": 3401154
},
- "routeReadyMedianMs": 649.5,
+ "routeReadyMedianMs": 646.0999999977648,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -205,15 +205,15 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 111.69999999925494,
+ "domContentLoadedMedianMs": 115.60000000149012,
"id": "editor-minimal",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 111.90000000223517,
- "longestTaskMaxMs": 179,
+ "loadMedianMs": 115.60000000149012,
+ "longestTaskMaxMs": 176,
"owner": "workbench",
- "projectSwitchMedianMs": 49.899999998509884,
+ "projectSwitchMedianMs": 53,
"readyMark": "invokeai:ready:widget:center:preview",
"remediationTicket": "deepen-widget-registry-loading",
"resourceBaseline": {
@@ -223,9 +223,9 @@
"largestAssetRawBytes": 746305,
"otherRawBytes": 136426,
"requestCount": 109,
- "scriptRawBytes": 3048378,
+ "scriptRawBytes": 3048854,
"scriptRequestCount": 104,
- "totalRawBytes": 3367003
+ "totalRawBytes": 3367479
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -234,11 +234,11 @@
"largestAssetRawBytes": 753769,
"otherRawBytes": 137791,
"requestCount": 109,
- "scriptRawBytes": 3078862,
+ "scriptRawBytes": 3079343,
"scriptRequestCount": 104,
- "totalRawBytes": 3400674
+ "totalRawBytes": 3401154
},
- "routeReadyMedianMs": 437.80000000074506,
+ "routeReadyMedianMs": 433.30000000074506,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
},
@@ -247,31 +247,31 @@
"cssRawBytes": 0,
"fontRawBytes": 0,
"imageRawBytes": 0,
- "largestAssetRawBytes": 135431,
+ "largestAssetRawBytes": 135416,
"otherRawBytes": 0,
"requestCount": 6,
- "scriptRawBytes": 284492,
+ "scriptRawBytes": 284477,
"scriptRequestCount": 6,
- "totalRawBytes": 284492
+ "totalRawBytes": 284477
},
"activatedResourceLimits": {
"cssRawBytes": 0,
"fontRawBytes": 0,
"imageRawBytes": 0,
- "largestAssetRawBytes": 136786,
+ "largestAssetRawBytes": 136771,
"otherRawBytes": 0,
"requestCount": 6,
- "scriptRawBytes": 287337,
+ "scriptRawBytes": 287322,
"scriptRequestCount": 6,
- "totalRawBytes": 287337
+ "totalRawBytes": 287322
},
- "domContentLoadedMedianMs": 111.69999999925494,
+ "domContentLoadedMedianMs": 110.89999999850988,
"id": "editor-canvas",
- "layoutAckMedianMs": 2.100000001490116,
- "layoutReturnSwitchMedianMs": 37.899999998509884,
- "layoutSwitchMedianMs": 69,
- "loadMedianMs": 111.89999999850988,
- "longestTaskMaxMs": 91,
+ "layoutAckMedianMs": 2.099999997764826,
+ "layoutReturnSwitchMedianMs": 36.70000000298023,
+ "layoutSwitchMedianMs": 68.69999999925494,
+ "loadMedianMs": 111,
+ "longestTaskMaxMs": 87,
"owner": "canvas",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:canvas",
@@ -283,9 +283,9 @@
"largestAssetRawBytes": 746305,
"otherRawBytes": 136426,
"requestCount": 115,
- "scriptRawBytes": 3332870,
+ "scriptRawBytes": 3333331,
"scriptRequestCount": 110,
- "totalRawBytes": 3651495
+ "totalRawBytes": 3651956
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -294,11 +294,11 @@
"largestAssetRawBytes": 753769,
"otherRawBytes": 137791,
"requestCount": 115,
- "scriptRawBytes": 3366199,
+ "scriptRawBytes": 3366665,
"scriptRequestCount": 110,
- "totalRawBytes": 3688010
+ "totalRawBytes": 3688476
},
- "routeReadyMedianMs": 995.1999999992549,
+ "routeReadyMedianMs": 994.0999999977648,
"scriptSourceOwnerSet": "editor-canvas-static",
"stateProfile": "empty"
},
@@ -307,31 +307,31 @@
"cssRawBytes": 0,
"fontRawBytes": 0,
"imageRawBytes": 0,
- "largestAssetRawBytes": 135431,
+ "largestAssetRawBytes": 135416,
"otherRawBytes": 0,
"requestCount": 6,
- "scriptRawBytes": 284492,
+ "scriptRawBytes": 284477,
"scriptRequestCount": 6,
- "totalRawBytes": 284492
+ "totalRawBytes": 284477
},
"activatedResourceLimits": {
"cssRawBytes": 0,
"fontRawBytes": 0,
"imageRawBytes": 0,
- "largestAssetRawBytes": 136786,
+ "largestAssetRawBytes": 136771,
"otherRawBytes": 0,
"requestCount": 6,
- "scriptRawBytes": 287337,
+ "scriptRawBytes": 287322,
"scriptRequestCount": 6,
- "totalRawBytes": 287337
+ "totalRawBytes": 287322
},
- "domContentLoadedMedianMs": 110.69999999925494,
+ "domContentLoadedMedianMs": 113,
"id": "editor-canvas",
- "layoutAckMedianMs": 2.300000000745058,
- "layoutReturnSwitchMedianMs": 37.69999999925494,
- "layoutSwitchMedianMs": 178.09999999776483,
- "loadMedianMs": 110.80000000074506,
- "longestTaskMaxMs": 351,
+ "layoutAckMedianMs": 2.699999999254942,
+ "layoutReturnSwitchMedianMs": 38.100000001490116,
+ "layoutSwitchMedianMs": 180.39999999850988,
+ "loadMedianMs": 113,
+ "longestTaskMaxMs": 384,
"owner": "canvas",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:canvas",
@@ -343,9 +343,9 @@
"largestAssetRawBytes": 746305,
"otherRawBytes": 136426,
"requestCount": 115,
- "scriptRawBytes": 3332870,
+ "scriptRawBytes": 3333331,
"scriptRequestCount": 110,
- "totalRawBytes": 3651495
+ "totalRawBytes": 3651956
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -354,11 +354,11 @@
"largestAssetRawBytes": 753769,
"otherRawBytes": 137791,
"requestCount": 115,
- "scriptRawBytes": 3366199,
+ "scriptRawBytes": 3366665,
"scriptRequestCount": 110,
- "totalRawBytes": 3688010
+ "totalRawBytes": 3688476
},
- "routeReadyMedianMs": 1220.3999999985099,
+ "routeReadyMedianMs": 1254.0999999977648,
"scriptSourceOwnerSet": "editor-canvas-static",
"stateProfile": "representative"
},
@@ -385,13 +385,13 @@
"scriptRequestCount": 7,
"totalRawBytes": 361200
},
- "domContentLoadedMedianMs": 111.5,
+ "domContentLoadedMedianMs": 120,
"id": "editor-workflow",
- "layoutAckMedianMs": 2.100000001490116,
- "layoutReturnSwitchMedianMs": 30.400000002235174,
- "layoutSwitchMedianMs": 85.19999999925494,
- "loadMedianMs": 111.80000000074506,
- "longestTaskMaxMs": 89,
+ "layoutAckMedianMs": 2.600000001490116,
+ "layoutReturnSwitchMedianMs": 33.899999998509884,
+ "layoutSwitchMedianMs": 95.39999999850988,
+ "loadMedianMs": 120.10000000149012,
+ "longestTaskMaxMs": 93,
"owner": "workflow",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:workflow",
@@ -403,9 +403,9 @@
"largestAssetRawBytes": 746305,
"otherRawBytes": 136426,
"requestCount": 117,
- "scriptRawBytes": 3390588,
+ "scriptRawBytes": 3391064,
"scriptRequestCount": 111,
- "totalRawBytes": 3724626
+ "totalRawBytes": 3725102
},
"resourceLimits": {
"cssRawBytes": 17748,
@@ -414,11 +414,11 @@
"largestAssetRawBytes": 753769,
"otherRawBytes": 137791,
"requestCount": 117,
- "scriptRawBytes": 3424494,
+ "scriptRawBytes": 3424975,
"scriptRequestCount": 111,
- "totalRawBytes": 3761873
+ "totalRawBytes": 3762354
},
- "routeReadyMedianMs": 1017,
+ "routeReadyMedianMs": 1062.5,
"scriptSourceOwnerSet": "editor-workflow-static",
"stateProfile": "empty"
},
@@ -445,13 +445,13 @@
"scriptRequestCount": 7,
"totalRawBytes": 361200
},
- "domContentLoadedMedianMs": 109.10000000149012,
+ "domContentLoadedMedianMs": 112,
"id": "editor-workflow",
- "layoutAckMedianMs": 2.2000000029802322,
- "layoutReturnSwitchMedianMs": 41,
- "layoutSwitchMedianMs": 131.80000000074506,
- "loadMedianMs": 109.10000000149012,
- "longestTaskMaxMs": 350,
+ "layoutAckMedianMs": 2.300000000745058,
+ "layoutReturnSwitchMedianMs": 39.80000000074506,
+ "layoutSwitchMedianMs": 132.19999999925494,
+ "loadMedianMs": 112,
+ "longestTaskMaxMs": 393,
"owner": "workflow",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:workflow",
@@ -463,9 +463,9 @@
"largestAssetRawBytes": 746305,
"otherRawBytes": 136426,
"requestCount": 117,
- "scriptRawBytes": 3390588,
+ "scriptRawBytes": 3391064,
"scriptRequestCount": 111,
- "totalRawBytes": 3724626
+ "totalRawBytes": 3725102
},
"resourceLimits": {
"cssRawBytes": 17748,
@@ -474,11 +474,11 @@
"largestAssetRawBytes": 753769,
"otherRawBytes": 137791,
"requestCount": 117,
- "scriptRawBytes": 3424494,
+ "scriptRawBytes": 3424975,
"scriptRequestCount": 111,
- "totalRawBytes": 3761873
+ "totalRawBytes": 3762354
},
- "routeReadyMedianMs": 1157.2000000029802,
+ "routeReadyMedianMs": 1158.9000000022352,
"scriptSourceOwnerSet": "editor-workflow-static",
"stateProfile": "representative"
},
@@ -505,13 +505,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 111.19999999925494,
+ "domContentLoadedMedianMs": 110.5,
"id": "editor-gallery",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
- "layoutSwitchMedianMs": 25.300000000745058,
- "loadMedianMs": 111.29999999701977,
- "longestTaskMaxMs": 87,
+ "layoutSwitchMedianMs": 25.900000002235174,
+ "loadMedianMs": 110.60000000149012,
+ "longestTaskMaxMs": 89,
"owner": "gallery",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:gallery",
@@ -523,9 +523,9 @@
"largestAssetRawBytes": 746305,
"otherRawBytes": 136426,
"requestCount": 109,
- "scriptRawBytes": 3048378,
+ "scriptRawBytes": 3048854,
"scriptRequestCount": 104,
- "totalRawBytes": 3367003
+ "totalRawBytes": 3367479
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -534,11 +534,11 @@
"largestAssetRawBytes": 753769,
"otherRawBytes": 137791,
"requestCount": 109,
- "scriptRawBytes": 3078862,
+ "scriptRawBytes": 3079343,
"scriptRequestCount": 104,
- "totalRawBytes": 3400674
+ "totalRawBytes": 3401154
},
- "routeReadyMedianMs": 1214.4000000022352,
+ "routeReadyMedianMs": 1220.1000000014901,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -565,13 +565,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 113.80000000074506,
+ "domContentLoadedMedianMs": 114.5,
"id": "editor-gallery",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
- "layoutSwitchMedianMs": 88,
- "loadMedianMs": 113.90000000223517,
- "longestTaskMaxMs": 165,
+ "layoutSwitchMedianMs": 88.19999999925494,
+ "loadMedianMs": 114.60000000149012,
+ "longestTaskMaxMs": 174,
"owner": "gallery",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:gallery",
@@ -583,9 +583,9 @@
"largestAssetRawBytes": 746305,
"otherRawBytes": 136426,
"requestCount": 109,
- "scriptRawBytes": 3048378,
+ "scriptRawBytes": 3048854,
"scriptRequestCount": 104,
- "totalRawBytes": 3367003
+ "totalRawBytes": 3367479
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -594,11 +594,11 @@
"largestAssetRawBytes": 753769,
"otherRawBytes": 137791,
"requestCount": 109,
- "scriptRawBytes": 3078862,
+ "scriptRawBytes": 3079343,
"scriptRequestCount": 104,
- "totalRawBytes": 3400674
+ "totalRawBytes": 3401154
},
- "routeReadyMedianMs": 1416.8999999985099,
+ "routeReadyMedianMs": 1427.3999999985099,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
}
@@ -807,6 +807,7 @@
"source:src/platform/pwa/registerServiceWorker.ts",
"source:src/platform/query/client.ts",
"source:src/platform/react/useMountEffect.ts",
+ "source:src/platform/react/usePreservedScrollOffset.ts",
"source:src/platform/react/useZodForm.ts",
"source:src/platform/search/dateTokens.ts",
"source:src/platform/state/accountLifecycle.ts",
@@ -1351,6 +1352,7 @@
"source:src/platform/react/composeProviders.tsx",
"source:src/platform/react/draftRegistry.ts",
"source:src/platform/react/useMountEffect.ts",
+ "source:src/platform/react/usePreservedScrollOffset.ts",
"source:src/platform/react/useZodForm.ts",
"source:src/platform/search/dateTokens.ts",
"source:src/platform/state/accountLifecycle.ts",
@@ -2243,6 +2245,7 @@
"source:src/platform/react/draftRegistry.ts",
"source:src/platform/react/useModifierHeld.ts",
"source:src/platform/react/useMountEffect.ts",
+ "source:src/platform/react/usePreservedScrollOffset.ts",
"source:src/platform/react/useZodForm.ts",
"source:src/platform/search/dateTokens.ts",
"source:src/platform/state/accountLifecycle.ts",
@@ -3301,6 +3304,7 @@
"source:src/platform/react/draftRegistry.ts",
"source:src/platform/react/useModifierHeld.ts",
"source:src/platform/react/useMountEffect.ts",
+ "source:src/platform/react/usePreservedScrollOffset.ts",
"source:src/platform/react/useZodForm.ts",
"source:src/platform/search/dateTokens.ts",
"source:src/platform/state/accountLifecycle.ts",
diff --git a/invokeai/frontend/webv2/scripts/run-accessibility-journeys.mjs b/invokeai/frontend/webv2/scripts/run-accessibility-journeys.mjs
index 9a0bd9926d..14d4102da0 100644
--- a/invokeai/frontend/webv2/scripts/run-accessibility-journeys.mjs
+++ b/invokeai/frontend/webv2/scripts/run-accessibility-journeys.mjs
@@ -120,11 +120,15 @@ const selectLayoutPreset = async (page, preset, centerView) => {
// Anchored at both ends, because custom presets share the strip: a loose
// `^Edit` also matches a user's "Edit copy". The optional suffix is the drift
// marker the tab folds into its own accessible name.
+ //
+ // Scoped to the strip: the Automate layout's workflow panel has its own "Edit"
+ // tab, so an unscoped tab lookup is ambiguous the moment a journey visits it.
const name = new RegExp(`^${preset}(, unsaved changes)?$`);
- const selected = page.getByRole('tab', { name, selected: true });
+ const strip = presetStrip(page);
+ const selected = strip.getByRole('tab', { name, selected: true });
if ((await selected.count()) === 0) {
- await page.getByRole('tab', { name }).click();
+ await strip.getByRole('tab', { name }).click();
}
await selected.waitFor();
@@ -644,6 +648,112 @@ const runVideoPreviewJourney = async (browser) => {
}
};
+/**
+ * State, not nodes.
+ *
+ * The shell keeps widgets mounted across layout switches so returning to a
+ * preset is cheap *and* lands where you left it. Node identity is the easy half
+ * and the automated suites already cover it; the half that actually regressed is
+ * the state those nodes carry. An unconditional `fitToView()` on surface attach
+ * and a scroll container that stops being rendered both throw it away, and
+ * neither is visible to a test that asserts the element is still there.
+ *
+ * Runs the real virtualized gallery and the real canvas engine, because that is
+ * where the loss happens.
+ */
+const runKeepAliveStateJourney = async (browser) => {
+ const { context, page, pageErrors } = await openRepresentativePage(browser, representativeProjectPath);
+ const id = 'workbench-keep-alive-state';
+
+ /**
+ * Every scroll offset in the panel, in DOM order. Restricted to real scroll
+ * containers — an overflow-clipped label is technically taller than its box
+ * and would otherwise wander into the comparison as noise.
+ */
+ const SCROLLER_QUERY = `(element) => [...element.querySelectorAll('*')].filter((node) => {
+ const overflowY = getComputedStyle(node).overflowY;
+ return (overflowY === 'auto' || overflowY === 'scroll') && node.scrollHeight > node.clientHeight + 40;
+ })`;
+
+ const readScrollOffsets = (panel) =>
+ panel.evaluate(
+ new Function('element', `return (${SCROLLER_QUERY})(element).map((node) => Math.round(node.scrollTop));`)
+ );
+
+ const scrollAll = (panel, offset) =>
+ panel.evaluate(
+ new Function(
+ 'element',
+ 'target',
+ `const scrollers = (${SCROLLER_QUERY})(element);
+ for (const scroller of scrollers) { scroller.scrollTop = target; }
+ return scrollers.map((scroller) => Math.round(scroller.scrollTop));`
+ ),
+ offset
+ );
+
+ try {
+ await waitForWorkbench(page);
+ await selectLayoutPreset(page, 'Compose', 'Preview');
+
+ const rightPanel = page.getByRole('complementary', { exact: true, name: 'right widget panel' });
+ const galleryItems = rightPanel.getByRole('list', { exact: true, name: 'Gallery items' });
+ await galleryItems.waitFor();
+
+ const leftPanel = page.getByRole('complementary', { exact: true, name: 'left widget panel' });
+ const scrolledLeftOffsets = await scrollAll(leftPanel, 400);
+ const scrolledOffsets = await scrollAll(rightPanel, 600);
+ assert.ok(
+ scrolledOffsets.length >= 2 && scrolledOffsets.every((offset) => offset > 0),
+ `The representative gallery must have scrollable boards and items; got ${JSON.stringify(scrolledOffsets)}.`
+ );
+ await waitForSettledDocument(page);
+
+ await selectLayoutPreset(page, 'Edit', 'Canvas');
+
+ const zoomTrigger = page.getByRole('button', { exact: true, name: 'Zoom level' });
+ await zoomTrigger.click();
+ await page.getByRole('menuitem', { exact: true, name: '200%' }).click();
+ await waitForSettledDocument(page);
+ assert.equal((await zoomTrigger.textContent())?.trim(), '200%', 'The zoom control must report the chosen zoom.');
+
+ // Away and back, which is the whole point of keeping the widgets mounted.
+ await selectLayoutPreset(page, 'Automate', 'Workflow');
+ await waitForSettledDocument(page);
+ await selectLayoutPreset(page, 'Edit', 'Canvas');
+ await waitForSettledDocument(page);
+
+ assert.equal(
+ (await zoomTrigger.textContent())?.trim(),
+ '200%',
+ 'Returning to a layout must keep the canvas viewport, not refit it.'
+ );
+
+ await selectLayoutPreset(page, 'Compose', 'Preview');
+ await galleryItems.waitFor();
+ await waitForSettledDocument(page);
+
+ assert.deepEqual(
+ await readScrollOffsets(rightPanel),
+ scrolledOffsets,
+ 'Returning to a layout must keep the gallery scrolled where the user left it.'
+ );
+ assert.deepEqual(
+ await readScrollOffsets(leftPanel),
+ scrolledLeftOffsets,
+ 'Returning to a layout must keep a panel body scrolled where the user left it.'
+ );
+
+ if (pageErrors.length > 0) {
+ throw new AggregateError(pageErrors, `${id} raised uncaught browser errors.`);
+ }
+
+ return { id, status: 'passed' };
+ } finally {
+ await context.close();
+ }
+};
+
const mockBackend = await startMockBackend(backendPort, { profile: 'representative' });
const preview = spawn(
'pnpm',
@@ -683,6 +793,9 @@ try {
if (!requestedJourney || requestedJourney === 'workbench-video-preview-representative') {
reports.push(await runVideoPreviewJourney(browser));
}
+ if (!requestedJourney || requestedJourney === 'workbench-keep-alive-state') {
+ reports.push(await runKeepAliveStateJourney(browser));
+ }
if (reports.length === 0) {
throw new Error(`Unknown accessibility journey ${JSON.stringify(requestedJourney)}.`);
}
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardsPanel.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardsPanel.tsx
index 6c93635dfc..9784f51f9e 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardsPanel.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardsPanel.tsx
@@ -4,6 +4,7 @@ import type { GalleryBoard } from '@features/gallery/core/types';
import { HStack, Icon, ScrollArea, Stack, Text } from '@chakra-ui/react';
import { toGalleryItemKey } from '@features/gallery/core/items';
+import { usePreservedScrollOffset } from '@platform/react/usePreservedScrollOffset';
import { IconButton } from '@platform/ui/Button';
import { Tooltip } from '@platform/ui/Tooltip';
import { PlusIcon } from 'lucide-react';
@@ -33,6 +34,11 @@ export const GalleryBoardsPanel = () => {
const [searchTerm, setSearchTerm] = useState('');
const [boardMenuTarget, setBoardMenuTarget] = useState<GalleryBoardMenuTarget | null>(null);
const searchInputRef = useRef<HTMLInputElement>(null);
+ const boardsViewportRef = useRef<HTMLDivElement>(null);
+
+ // The shell keeps the gallery mounted across layout switches, and a scroll
+ // container that stops being rendered loses its offset outright.
+ usePreservedScrollOffset(boardsViewportRef);
const { collapsedBoardSections, showArchivedBoards, showDateBoards } = gallery.settings;
@@ -138,7 +144,7 @@ export const GalleryBoardsPanel = () => {
onSubmitSearch={handleSubmitSearch}
/>
<ScrollArea.Root flex="1" minH="0" size="xs" variant="hover" w="full">
- <ScrollArea.Viewport h="full" w="full">
+ <ScrollArea.Viewport ref={boardsViewportRef} h="full" w="full">
<ScrollArea.Content {...SCROLL_CONTENT_PROPS}>
<GalleryBoardSection
action={addBoardAction}
diff --git a/invokeai/frontend/webv2/src/platform/react/usePreservedScrollOffset.browser.test.tsx b/invokeai/frontend/webv2/src/platform/react/usePreservedScrollOffset.browser.test.tsx
new file mode 100644
index 0000000000..60cd5a2015
--- /dev/null
+++ b/invokeai/frontend/webv2/src/platform/react/usePreservedScrollOffset.browser.test.tsx
@@ -0,0 +1,125 @@
+import { act, Activity, useRef } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, describe, expect, it } from 'vitest';
+
+import { usePreservedScrollOffset } from './usePreservedScrollOffset';
+
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+const VIEWPORT_STYLE = { height: '100px', overflow: 'auto', width: '100px' } as const;
+
+/**
+ * Stands in for a virtualized list: the scrollable content is sized from a
+ * measurement, so it does not survive the container being taken out of layout.
+ * That is what defeats the browser's own scroll restoration, and a container
+ * with fixed content would not reproduce the bug at all.
+ */
+const Scroller = ({ contentHeight, isPreserved }: { contentHeight: number; isPreserved: boolean }) => {
+ const preservedRef = useRef<HTMLDivElement>(null);
+ const plainRef = useRef<HTMLDivElement>(null);
+
+ usePreservedScrollOffset(isPreserved ? preservedRef : plainRef);
+
+ return (
+ <div ref={isPreserved ? preservedRef : undefined} data-testid="scroller" style={VIEWPORT_STYLE}>
+ <div style={{ height: `${String(contentHeight)}px` }} />
+ </div>
+ );
+};
+
+let host: HTMLDivElement | null = null;
+let root: Root | null = null;
+
+const render = async (mode: 'hidden' | 'visible', contentHeight: number, isPreserved: boolean) => {
+ await act(async () => {
+ root?.render(
+ <Activity mode={mode}>
+ <Scroller contentHeight={contentHeight} isPreserved={isPreserved} />
+ </Activity>
+ );
+ await new Promise((resolve) => {
+ requestAnimationFrame(resolve);
+ });
+ });
+};
+
+const scroller = () => {
+ const element = host?.querySelector<HTMLDivElement>('[data-testid="scroller"]');
+
+ if (!element) {
+ throw new Error('Expected the scroll container to be mounted.');
+ }
+
+ return element;
+};
+
+/** Scrolls and lets the real scroll event land, the way a user gesture would. */
+const scrollTo = async (offset: number) => {
+ const element = scroller();
+
+ await act(async () => {
+ element.scrollTop = offset;
+ await new Promise((resolve) => {
+ requestAnimationFrame(resolve);
+ });
+ });
+};
+
+/** Hides the container, collapses its measured content, then shows it again. */
+const hideAndShow = async (isPreserved: boolean) => {
+ await render('hidden', 0, isPreserved);
+ await render('visible', 2000, isPreserved);
+};
+
+const mount = () => {
+ host = document.createElement('div');
+ host.style.cssText = 'height:200px;width:200px;';
+ document.body.append(host);
+ root = createRoot(host);
+};
+
+afterEach(async () => {
+ await act(async () => {
+ root?.unmount();
+ await Promise.resolve();
+ });
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+describe('preserved scroll offset', () => {
+ it('keeps the offset across a keep-alive hide and show', async () => {
+ mount();
+ await render('visible', 2000, true);
+ await scrollTo(500);
+
+ const element = scroller();
+
+ await hideAndShow(true);
+
+ // The state, not the node: identity alone was never the thing at risk.
+ //
+ // Chrome restores this much on its own when the scrollable content happens
+ // to survive, so this pins the contract rather than reproducing the bug —
+ // the real reproduction is the `workbench-keep-alive-state` journey, which
+ // runs the actual virtualized gallery.
+ expect(scroller()).toBe(element);
+ expect(element.scrollTop).toBe(500);
+ });
+
+ it('does not carry an offset into a genuinely new instance', async () => {
+ mount();
+ await render('visible', 2000, true);
+ await scrollTo(500);
+
+ await act(async () => {
+ root?.unmount();
+ await Promise.resolve();
+ });
+ root = createRoot(host as HTMLDivElement);
+ await render('visible', 2000, true);
+
+ expect(scroller().scrollTop).toBe(0);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/platform/react/usePreservedScrollOffset.ts b/invokeai/frontend/webv2/src/platform/react/usePreservedScrollOffset.ts
new file mode 100644
index 0000000000..a5fbf71bf7
--- /dev/null
+++ b/invokeai/frontend/webv2/src/platform/react/usePreservedScrollOffset.ts
@@ -0,0 +1,47 @@
+import { useLayoutEffect, useRef, type RefObject } from 'react';
+
+/**
+ * Keeps a scroll container's offset across the container ceasing to be rendered.
+ *
+ * The shell keeps widgets mounted across layout switches and hides them with
+ * `display: none`, which takes the element out of layout entirely: it has no
+ * scrollable overflow, its `scrollTop` reads 0, and the browser's own scroll
+ * restoration only survives if the scrollable content happens to be unchanged
+ * when it comes back. A virtualized list sizes its content from a measured
+ * viewport, so its content is not unchanged, and the offset is simply lost —
+ * the list returns pinned to the top with no scroll event ever having fired.
+ *
+ * The offset is tracked as the user scrolls rather than read back at teardown,
+ * because by the time a hidden subtree's effects are cleaned up the element is
+ * already out of layout and reports `scrollTop` as 0 — reading it there records
+ * nothing. Restoring happens in a layout effect, which runs whenever the subtree
+ * is shown again (a real remount and a keep-alive reveal are indistinguishable
+ * here, and both want the same thing) and lands before paint, so the list never
+ * shows a frame at the top.
+ *
+ * Scoped to one component instance by construction: a genuine unmount takes the
+ * remembered offset with it, exactly as before.
+ */
+export const usePreservedScrollOffset = (ref: RefObject<HTMLElement | null>): void => {
+ const offsetRef = useRef(0);
+
+ useLayoutEffect(() => {
+ const element = ref.current;
+
+ if (!element) {
+ return;
+ }
+
+ if (offsetRef.current > 0) {
+ element.scrollTop = offsetRef.current;
+ }
+
+ const recordOffset = () => {
+ offsetRef.current = element.scrollTop;
+ };
+
+ element.addEventListener('scroll', recordOffset, { passive: true });
+
+ return () => element.removeEventListener('scroll', recordOffset);
+ }, [ref]);
+};
diff --git a/invokeai/frontend/webv2/src/platform/ui/Scrollable.tsx b/invokeai/frontend/webv2/src/platform/ui/Scrollable.tsx
index cf86c670da..de1206ab35 100644
--- a/invokeai/frontend/webv2/src/platform/ui/Scrollable.tsx
+++ b/invokeai/frontend/webv2/src/platform/ui/Scrollable.tsx
@@ -1,6 +1,8 @@
-import type { ComponentProps, ReactNode, Ref } from 'react';
+import type { ComponentProps, ReactNode, RefObject } from 'react';
import { ScrollArea } from '@chakra-ui/react';
+import { usePreservedScrollOffset } from '@platform/react/usePreservedScrollOffset';
+import { useRef } from 'react';
type ScrollAreaRootProps = ComponentProps<typeof ScrollArea.Root>;
type ScrollAreaContentProps = ComponentProps<typeof ScrollArea.Content>;
@@ -26,16 +28,33 @@ export const Scrollable = ({
/** Scroll axis; the scrollbar and content sizing follow it. Defaults to vertical. */
orientation?: 'horizontal' | 'vertical';
/** The scrolling element itself — what a virtualizer needs to observe. */
- viewportRef?: Ref<HTMLDivElement>;
-}) => (
- <ScrollArea.Root size="xs" variant="hover" {...rootProps}>
- <ScrollArea.Viewport aria-label={label} h="full" ref={viewportRef} role={label ? 'region' : undefined} w="full">
- <ScrollArea.Content w={orientation === 'horizontal' ? 'max-content' : 'full'} {...contentProps}>
- {children}
- </ScrollArea.Content>
- </ScrollArea.Viewport>
- <ScrollArea.Scrollbar orientation={orientation}>
- <ScrollArea.Thumb />
- </ScrollArea.Scrollbar>
- </ScrollArea.Root>
-);
+ viewportRef?: RefObject<HTMLDivElement | null>;
+}) => {
+ const fallbackViewportRef = useRef<HTMLDivElement | null>(null);
+ // One ref, shared with the caller when it wants one, so nothing has to merge
+ // or reassign refs during render.
+ const resolvedViewportRef = viewportRef ?? fallbackViewportRef;
+
+ // The shell keeps widgets mounted across layout switches, and a scroll
+ // container that stops being rendered loses its offset outright.
+ usePreservedScrollOffset(resolvedViewportRef);
+
+ return (
+ <ScrollArea.Root size="xs" variant="hover" {...rootProps}>
+ <ScrollArea.Viewport
+ aria-label={label}
+ h="full"
+ ref={resolvedViewportRef}
+ role={label ? 'region' : undefined}
+ w="full"
+ >
+ <ScrollArea.Content w={orientation === 'horizontal' ? 'max-content' : 'full'} {...contentProps}>
+ {children}
+ </ScrollArea.Content>
+ </ScrollArea.Viewport>
+ <ScrollArea.Scrollbar orientation={orientation}>
+ <ScrollArea.Thumb />
+ </ScrollArea.Scrollbar>
+ </ScrollArea.Root>
+ );
+};
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts
index 1f6ae88135..0a7019b3a4 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts
@@ -150,6 +150,12 @@ export interface CanvasPsdExportCapability {
export interface CanvasViewportCapability {
getViewport(): Viewport;
fitToView(): void;
+ /**
+ * Fits the document into view only the first time this engine is shown.
+ * Surfaces attach on every re-show of a kept-alive widget; an unconditional
+ * fit there would discard the user's zoom and pan.
+ */
+ fitToViewOnFirstShow(): void;
setBboxGrid(size: number): void;
}
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.ts
index b9fd0ceccb..bb093e28cc 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.ts
@@ -13719,6 +13719,37 @@ describe('fitToView: content ∪ bbox', () => {
expect(engine.viewport.getViewport().getZoom()).toBeCloseTo(0.304, 2);
engine.lifecycle.dispose();
});
+
+ it('fits on the first show only, so a re-shown canvas keeps its zoom and pan', () => {
+ const { store } = createReactiveStore(noLayerDoc());
+ const engine = createCanvasEngine({
+ backend: createTestStubRasterBackend(),
+ bitmapStore: createSpyBitmapStore(),
+ imageResolver: () => Promise.resolve(new Blob()),
+ projectId: 'p1',
+ store,
+ });
+ engine.surface.resize(400, 400, 1);
+
+ engine.viewport.fitToViewOnFirstShow();
+ const fittedZoom = engine.viewport.getViewport().getZoom();
+ engine.viewport.getViewport().zoomAtPoint(2, { x: 200, y: 200 });
+ engine.viewport.getViewport().panBy({ x: 30, y: -20 });
+ const pannedView = engine.viewport.getViewport().getState();
+
+ // A surface attaches again every time the shell re-shows a kept widget.
+ engine.viewport.fitToViewOnFirstShow();
+
+ expect(fittedZoom).not.toBeCloseTo(2, 2);
+ expect(engine.viewport.getViewport().getZoom()).toBeCloseTo(2, 2);
+ expect(engine.viewport.getViewport().getState()).toEqual(pannedView);
+
+ // The explicit control still fits unconditionally.
+ engine.viewport.fitToView();
+
+ expect(engine.viewport.getViewport().getZoom()).toBeCloseTo(fittedZoom, 2);
+ engine.lifecycle.dispose();
+ });
});
// ---- transform session: param commit (image) + pixel bake (paint) ----------
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts
index 4041666a62..a9cdf7146b 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts
@@ -1812,6 +1812,8 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngineCoreC
render({ all: true, damage: null, layers: new Set<string>(), overlay: true, view: true });
};
+ let hasEverFitToView = false;
+
const fitToView = (): void => {
const doc = mirror.getDocument();
if (!doc) {
@@ -1827,6 +1829,26 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngineCoreC
}
}
viewport.fitToView(bounds, viewport.getViewportSize());
+ hasEverFitToView = true;
+ };
+
+ /**
+ * Fits the document into view only if this engine has never fitted it.
+ *
+ * A surface attaches every time the canvas widget is put on screen, and the
+ * shell keeps widgets mounted across layout switches — so returning to a
+ * layout re-attaches the surface and an unconditional fit would throw away
+ * whatever zoom and pan the user had set. The engine outlives the hide (it is
+ * leased per project and released with a grace period), so it is the thing
+ * that knows whether this is genuinely the canvas's first showing. A fresh
+ * engine has no viewport worth preserving and fits as before.
+ */
+ const fitToViewOnFirstShow = (): void => {
+ if (hasEverFitToView) {
+ return;
+ }
+
+ fitToView();
};
const isLayerCacheReadyForOp = (layer: CanvasLayerContract, doc: CanvasDocumentContractV2): boolean => {
@@ -2364,7 +2386,7 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngineCoreC
},
});
const surface: CanvasSurfaceCapability = { attach, detach, resize };
- const viewportCapability: CanvasViewportCapability = { fitToView, getViewport, setBboxGrid };
+ const viewportCapability: CanvasViewportCapability = { fitToView, fitToViewOnFirstShow, getViewport, setBboxGrid };
const historyCapability: CanvasHistoryCapability = { clearHistory, redo, undo };
const lifecycle: CanvasLifecycleCapability = {
activate,
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasSurface.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasSurface.tsx
index 473c7004dd..e69c55064d 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasSurface.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasSurface.tsx
@@ -73,10 +73,11 @@ export const CanvasSurface = ({ engine }: { engine: CanvasSurfaceEngine }) => {
};
syncSize();
- // Fit the document into view on first attach, once the viewport is sized.
- if (engine.document.getDocument()) {
- engine.viewport.fitToView();
- }
+ // Fit the document into view the first time this canvas is shown, once the
+ // viewport is sized. The shell keeps widgets mounted across layout switches,
+ // so this callback re-runs on every re-show and an unconditional fit would
+ // reset the user's zoom and pan each time they came back.
+ engine.viewport.fitToViewOnFirstShow();
const observer = new ResizeObserver(syncSize);
observer.observe(container);