Commit 4a73e9c
perf(frontend): message windowing + stable keys in MessagesTab (#819)
## Summary
Addresses UI bogging-down and potential memory pressure caused by
accumulating large numbers of AG-UI events in long-running sessions.
- **Message windowing**: cap the rendered DOM to the last 100 messages
(`MAX_VISIBLE_MESSAGES`). A lightweight "Load earlier messages" button
reveals older history on demand, keeping the number of mounted React
subtrees bounded regardless of session length
- **Scroll position preservation**: `useLayoutEffect` + explicit
`scrollTop` assignment anchors the viewport when loading earlier
messages, overriding browser scroll-anchoring to get deterministic
behavior
- **Stable React keys**: replace `key={sm-${idx}}` (index-based) with
IDs derived from the message itself. Index keys cause React to re-render
every message below an insertion point; stable keys mean only the
changed node is reconciled
- **`handleScroll` guard**: `setIsAtBottom` now uses a functional update
that short-circuits when the boolean value hasn't changed, eliminating
the re-render triggered on every scroll event
- **`streamMessages` useMemo split**: the single O(n) memo that ran on
every text delta is split into `committedStreamMessages` (hierarchy
traversal, runs infrequently) and `streamMessages` (O(1) append, runs on
every `TEXT_MESSAGE_CONTENT` event)
## Jira
https://issues.redhat.com/browse/RHOAIENG-52026
## Test plan
- [ ] Open a session with a large number of messages; confirm only the
latest 100 are rendered (use DevTools Elements panel to count)
- [ ] Click "Load earlier messages"; confirm the viewport stays anchored
to the same content and doesn't jump to the top
- [ ] Verify new streaming messages still auto-scroll when the user is
at the bottom
- [ ] Verify the empty-state placeholder appears for sessions with no
messages
- [ ] Confirm system-message toggle still works with the windowed list
- [ ] React DevTools Profiler: confirm `committedStreamMessages` does
not re-run on `TEXT_MESSAGE_CONTENT` events
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>1 parent 8d50ead commit 4a73e9c
2 files changed
Lines changed: 127 additions & 41 deletions
File tree
- components/frontend/src
- app/projects/[name]/sessions/[sessionName]
- components/session
Lines changed: 43 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
775 | 775 | | |
776 | 776 | | |
777 | 777 | | |
778 | | - | |
779 | | - | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
780 | 782 | | |
781 | 783 | | |
782 | 784 | | |
| |||
1043 | 1045 | | |
1044 | 1046 | | |
1045 | 1047 | | |
1046 | | - | |
1047 | | - | |
1048 | | - | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
1052 | | - | |
1053 | | - | |
1054 | | - | |
1055 | | - | |
1056 | | - | |
1057 | | - | |
1058 | | - | |
1059 | | - | |
1060 | | - | |
1061 | | - | |
1062 | | - | |
1063 | | - | |
1064 | | - | |
1065 | | - | |
1066 | | - | |
1067 | | - | |
1068 | | - | |
1069 | | - | |
1070 | | - | |
1071 | | - | |
1072 | | - | |
1073 | 1048 | | |
1074 | 1049 | | |
1075 | 1050 | | |
| |||
1161 | 1136 | | |
1162 | 1137 | | |
1163 | 1138 | | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
1164 | 1178 | | |
1165 | 1179 | | |
1166 | 1180 | | |
1167 | | - | |
1168 | | - | |
1169 | | - | |
1170 | 1181 | | |
1171 | 1182 | | |
1172 | 1183 | | |
| |||
Lines changed: 84 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | | - | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
13 | 28 | | |
14 | 29 | | |
15 | | - | |
| 30 | + | |
16 | 31 | | |
17 | 32 | | |
18 | 33 | | |
| |||
43 | 58 | | |
44 | 59 | | |
45 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
46 | 67 | | |
47 | 68 | | |
48 | 69 | | |
| |||
55 | 76 | | |
56 | 77 | | |
57 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
58 | 87 | | |
59 | 88 | | |
60 | 89 | | |
61 | 90 | | |
62 | | - | |
63 | | - | |
| 91 | + | |
64 | 92 | | |
65 | 93 | | |
66 | 94 | | |
67 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
68 | 98 | | |
69 | 99 | | |
70 | 100 | | |
| |||
74 | 104 | | |
75 | 105 | | |
76 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
77 | 133 | | |
78 | 134 | | |
79 | 135 | | |
| |||
137 | 193 | | |
138 | 194 | | |
139 | 195 | | |
140 | | - | |
141 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
142 | 217 | | |
143 | 218 | | |
144 | 219 | | |
| |||
176 | 251 | | |
177 | 252 | | |
178 | 253 | | |
179 | | - | |
| 254 | + | |
180 | 255 | | |
181 | 256 | | |
182 | 257 | | |
| |||
0 commit comments