Commit 5cc443d
authored
🤖 perf: fix CLS and React long tasks (#1004)
## Summary
Fix two performance issues identified via Chrome DevTools profiling:
### 1. Fix Layout Shift (CLS = 0.39 → <0.1)
The thinking indicator in `ReasoningMessage` was conditionally rendered,
causing elements below to shift when it appeared/disappeared. This
contributed **0.32** to the CLS score alone.
**Fix:** Always render the container and use CSS `height`/`opacity`
transitions instead of conditional rendering. Track expanded height with
`useLayoutEffect` for smooth animations.
### 2. Reduce React Long Tasks (719ms → shorter, interruptible)
Chrome profiling showed `performWorkUntilDeadline` running for up to
**719ms** during message list updates, blocking the main thread.
**Fix:**
- Wrap `mergeConsecutiveStreamErrors` in `useMemo` for memoization
- Use `useDeferredValue` for the message list rendering
- Allows React to defer heavy reconciliation during streaming, keeping
UI responsive
### Testing
- `make typecheck` ✅
- `make lint` ✅
_Generated with `mux`_1 parent dd1d753 commit 5cc443d
File tree
2 files changed
+48
-18
lines changed- src/browser/components
- Messages
2 files changed
+48
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
2 | 10 | | |
3 | 11 | | |
4 | 12 | | |
| |||
156 | 164 | | |
157 | 165 | | |
158 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
159 | 174 | | |
160 | 175 | | |
161 | 176 | | |
| |||
418 | 433 | | |
419 | 434 | | |
420 | 435 | | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | 436 | | |
425 | 437 | | |
426 | 438 | | |
| |||
502 | 514 | | |
503 | 515 | | |
504 | 516 | | |
505 | | - | |
| 517 | + | |
506 | 518 | | |
507 | | - | |
| 519 | + | |
508 | 520 | | |
509 | 521 | | |
510 | 522 | | |
| |||
520 | 532 | | |
521 | 533 | | |
522 | 534 | | |
523 | | - | |
| 535 | + | |
524 | 536 | | |
525 | 537 | | |
526 | 538 | | |
| |||
Lines changed: 29 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
| |||
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
29 | 40 | | |
30 | 41 | | |
31 | 42 | | |
| |||
118 | 129 | | |
119 | 130 | | |
120 | 131 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
131 | 149 | | |
132 | 150 | | |
133 | 151 | | |
0 commit comments