Commit 92feb24
authored
perf(workflow): scope resize CSS-var writes to the container, not :root (#5738)
* perf(workflow): scope resize CSS-var writes to the container, not :root
Resizing the editor panel, terminal, output panel, and sidebar was still
laggy on large workflows even after the drag handles stopped re-rendering
React per frame. A CDP trace showed the cost was style recalculation, not
JS or layout: ~3.9s of Document::recalcStyle over a 50-move panel drag.
Root cause: each drag frame wrote its CSS variable to document.documentElement.
On a large document (~42k elements) any inline custom-property write on the
<html> root recalculates style for the whole tree — measured at ~77ms per
write, independent of what actually reads the variable (an unused var costs
the same). Writing the same variable to the element that consumes it recalcs
only that subtree (~0.5ms) — a ~150x reduction.
useDragResize now writes the variable to a caller-provided target element
during the drag and reconciles to :root once on release (so on-demand readers
and the pre-hydration script are unchanged): panel -> .panel-container,
terminal -> .terminal-container, output panel -> .terminal-container (both
consumers inherit it), sidebar -> .sidebar-shell-outer. The terminal's
expanded-threshold sync writes store state directly instead of setTerminalHeight
so it no longer touches :root mid-drag.
Measured (near-empty canvas, 50-move drag): panel style+layout 3891ms -> 56ms,
frame p95 91.6ms -> 8.4ms, main-thread blocking 4566ms -> 0ms; terminal
recalc 3899ms -> 16ms, blocking 5558ms -> 0ms; sidebar recalc ~77ms/frame -> ~1ms/frame.
* perf(workflow): keep float boundary-sync live during scoped resize drags
The resize hooks now write their CSS variable to the consuming container
element during a drag (not :root), so use-float-boundary-sync's MutationObserver
on :root no longer fired mid-drag and open floats (chat, search-replace,
variables) only re-clamped on release. Read each boundary dimension from its
scoped element with a :root fallback, and observe the container elements as
well as :root, so an open float tracks the drag live exactly as before.
* fix(workflow): finalize drag on unmount + clamp reads scoped output width
- useDragResize: unmounting mid-drag now runs endDrag (commit + drop the
scoped override) instead of a bare cleanup, so navigating away can neither
lose the resize nor strand an inline override on a surviving target element.
- terminal output-panel clamp: read the live --output-panel-width from the
terminal element first (where a drag writes its scoped override), then :root,
then the store, so a mid-drag terminal/window resize can't clamp against a
stale value.
* fix(workflow): robust drag finalize — last-applied value, sidebar unmount, clamp skip
Addresses three review findings on the scoped-resize change:
- useDragResize: track the last applied value and commit that on release;
only recompute from the pointer event while the target is still connected.
On an unmount the target's rect can be detached, so a layout-reading compute
(e.g. the output panel's) would return a degenerate MIN — committing the last
shown value avoids persisting the wrong width, and keeps flick-safety on a
normal release.
- use-sidebar-resize: finalize on unmount (run endDrag, not bare cleanup) so a
drag interrupted by unmount persists the width and drops the scoped override.
This matters more than for the panel/terminal because .sidebar-shell-outer
lives in the workspace chrome and outlives the sidebar, so a stranded override
would win over :root.
- terminal output-panel clamp: skip while an output-panel drag is active (its
scoped inline override is present). That drag's own compute clamps every frame
against the live terminal rect, and a store-driven :root write here would be
masked by the inline override anyway.
* fix(workflow): sidebar flick-safety + clamp reads committed :root width
- use-sidebar-resize: compute the clamped width synchronously on each pointer
move (storing lastWidth) and defer only the DOM write to rAF, so a fast flick
released before the frame runs still commits the final pointer position
instead of a stale frame or nothing.
- terminal output-panel clamp: when not mid-drag, read the committed
--output-panel-width from :root (written synchronously by the store setter)
rather than the React store value, which lags a render behind the commit;
fall back to the store before any commit. Comment corrected to match.1 parent 3453692 commit 92feb24
7 files changed
Lines changed: 193 additions & 116 deletions
File tree
- apps/sim
- app/workspace/[workspaceId]/w
- [workflowId]
- components
- panel/hooks
- terminal
- hooks
- hooks/float
- components/sidebar/hooks
- hooks
Lines changed: 10 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
25 | | - | |
26 | | - | |
27 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| |||
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
| 35 | + | |
| 36 | + | |
36 | 37 | | |
37 | | - | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
Lines changed: 13 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | 6 | | |
16 | 7 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
22 | 15 | | |
23 | 16 | | |
24 | 17 | | |
25 | 18 | | |
26 | 19 | | |
27 | | - | |
| 20 | + | |
28 | 21 | | |
29 | | - | |
30 | | - | |
31 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
32 | 25 | | |
33 | 26 | | |
34 | 27 | | |
| |||
42 | 35 | | |
43 | 36 | | |
44 | 37 | | |
| 38 | + | |
| 39 | + | |
45 | 40 | | |
46 | | - | |
47 | 41 | | |
48 | | - | |
49 | 42 | | |
50 | 43 | | |
Lines changed: 23 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
16 | 21 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
22 | 29 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
28 | 33 | | |
29 | | - | |
| 34 | + | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
34 | | - | |
35 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
36 | 43 | | |
37 | 44 | | |
38 | 45 | | |
| |||
41 | 48 | | |
42 | 49 | | |
43 | 50 | | |
| 51 | + | |
| 52 | + | |
44 | 53 | | |
45 | | - | |
46 | 54 | | |
| 55 | + | |
47 | 56 | | |
48 | 57 | | |
Lines changed: 13 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1255 | 1255 | | |
1256 | 1256 | | |
1257 | 1257 | | |
1258 | | - | |
1259 | | - | |
1260 | | - | |
1261 | | - | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
1262 | 1267 | | |
1263 | 1268 | | |
1264 | 1269 | | |
| |||
1267 | 1272 | | |
1268 | 1273 | | |
1269 | 1274 | | |
| 1275 | + | |
| 1276 | + | |
1270 | 1277 | | |
1271 | 1278 | | |
1272 | 1279 | | |
| |||
1275 | 1282 | | |
1276 | 1283 | | |
1277 | 1284 | | |
1278 | | - | |
| 1285 | + | |
1279 | 1286 | | |
1280 | 1287 | | |
1281 | | - | |
| 1288 | + | |
1282 | 1289 | | |
1283 | 1290 | | |
1284 | 1291 | | |
| |||
Lines changed: 36 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
18 | 38 | | |
19 | 39 | | |
20 | 40 | | |
| |||
30 | 50 | | |
31 | 51 | | |
32 | 52 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
42 | 56 | | |
43 | 57 | | |
44 | 58 | | |
| |||
83 | 97 | | |
84 | 98 | | |
85 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
86 | 105 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
91 | 111 | | |
92 | 112 | | |
93 | 113 | | |
| |||
Lines changed: 28 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | | - | |
| 21 | + | |
| 22 | + | |
19 | 23 | | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
25 | | - | |
26 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
27 | 34 | | |
28 | 35 | | |
29 | 36 | | |
30 | | - | |
| 37 | + | |
31 | 38 | | |
32 | 39 | | |
33 | 40 | | |
34 | | - | |
| 41 | + | |
35 | 42 | | |
36 | 43 | | |
37 | 44 | | |
38 | 45 | | |
| 46 | + | |
| 47 | + | |
39 | 48 | | |
40 | 49 | | |
41 | 50 | | |
42 | 51 | | |
43 | 52 | | |
44 | 53 | | |
45 | 54 | | |
| 55 | + | |
46 | 56 | | |
47 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
48 | 61 | | |
49 | 62 | | |
50 | | - | |
51 | | - | |
52 | | - | |
| 63 | + | |
53 | 64 | | |
54 | 65 | | |
55 | 66 | | |
| |||
68 | 79 | | |
69 | 80 | | |
70 | 81 | | |
71 | | - | |
| 82 | + | |
72 | 83 | | |
73 | 84 | | |
74 | 85 | | |
75 | 86 | | |
76 | | - | |
77 | | - | |
78 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
79 | 91 | | |
80 | 92 | | |
81 | | - | |
| 93 | + | |
82 | 94 | | |
83 | 95 | | |
84 | 96 | | |
| |||
87 | 99 | | |
88 | 100 | | |
89 | 101 | | |
90 | | - | |
| 102 | + | |
91 | 103 | | |
92 | 104 | | |
93 | 105 | | |
0 commit comments