Repository navigation
Conversation
There was a problem hiding this comment.
The crash is fixed, but the new regression test is broken and needs fixing before merge.
I checked it with a component test compiled with Solid's real compiler. It mounts a growing steer user-message row, then removes its key so an assistant-part row takes the same index. On the base this throws Expected a user-message timeline row; with this PR there's no error. The virtualizer.tsx change alone also prevents it, and so does pinning the row in Row. tsc -b passes for packages/app. For packages/session-ui it passes apart from errors in the new test.
Public API: unchanged.
Concerns:
- The new test is broken and stops other tests from running. Details inline.
- The tag fallback in every branch isn't needed. Once
Rowpins its row by key, the tag can't change inside a branch. Details inline.
|
|
||
| const rowKey = "user-message:msg_2" | ||
| const index = initial.rows.findIndex((item) => TimelineRow.key(item) === rowKey) | ||
| const initialRow = initial.rowByKey.get(rowKey)! |
There was a problem hiding this comment.
This test can't pass: Timeline.constructSessionMessageRows returns { activeMessageID, turnPhaseByID, rows } with no rowByKey. It throws TypeError: undefined is not an object here, and tsc -b reports the same error (plus parentID on the assistant message).
The import on line 7 also brings the whole renderer .tsx into a test file that so far only covered row-building. Under the package's bun test src (no browser conditions), that import causes an unhandled error, and the other 62 tests in this file stop running.
The test also only checks the small pinTimelineRow helper, not the cleanup path that crashed. I'd drop it, or rebuild rowByKey from rows and move it, together with pinTimelineRow, somewhere that doesn't import the renderer (e.g. timeline-row.ts).
| const value = row() | ||
|
|
||
| if (!Predicate.isTagged(value, "UserMessage")) throw new Error("Expected a user-message timeline row") | ||
| if (Predicate.isTagged(value, "UserMessage")) last = value |
There was a problem hiding this comment.
Once Row passes pinTimelineRow(props.row, key), a branch only ever sees rows with its own key, and the key includes the tag. So this 'keep the last matching row' fallback, repeated in every branch, can no longer be reached. What it does change is that a real invariant violation would now be silently hidden instead of throwing. I checked that the virtualizer change and the Row pinning each fix the crash on their own. I'd keep the original throws in these current() helpers so the fix stays minimal.
…eline row changes type Fixes anomalyco#62800
bde3f1c to
af1f6a2
Compare
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
There was a problem hiding this comment.
Both earlier points are addressed. The regression test now builds its key map from rows and only imports TimelineRow.pin from timeline-row.ts, so it passes and the rest of the file runs again. The strict tag checks in each branch's current() are back, and the fix now relies on Row pinning each keyed branch to its own row.
I re-ran my component test, compiled with Solid's real compiler. A growing steer user-message row has its key removed while an assistant-part row takes the same index. On the base it still throws Expected a user-message timeline row; with this PR there's no error. bun test src/timeline in packages/session-ui passes, and tsc -b printed no errors for packages/session-ui or packages/app.
Public API: unchanged.
No new concerns.
Issue for this PR
Closes #62800
Type of change
What does this PR do?
Fixes the fatal
Error: Expected a user-message timeline rowcrash when a virtualized timeline row's key disappears and another row type lands at the same index in the same reactive batch (for example when a steered user message row is replaced by an assistant/thinking row).VirtualRow(packages/app/src/session/timeline/virtualizer.tsx), fall back toinitialRowinstead ofrows()[item().index]whenrowByKey().get(rowProps.rowKey)isundefined, preventingVirtualRowfrom handing a different row variant at the same index to a still-mounted keyed branch before<For>unmounts it.TimelineRow.pin(packages/session-ui/src/timeline/timeline-row.ts) and wrapprops.rowinRow(packages/session-ui/src/timeline/session-timeline-row.tsx) inside<Show when={TimelineRow.key(props.row())} keyed>so each keyed branch stays pinned to its own key while keeping the strict tag checks incurrent().props.row.userMessageIDeagerly inFramebefore schedulinggrowIn'srequestAnimationFramecallback.How did you verify your code works?
Added a unit test in
packages/session-ui/src/timeline/rows-current.test.tsverifying thatTimelineRow.pinpreserves the keyedUserMessagerow whenconstructSessionMessageRowsreplaces the row at the same index with an assistant/thinking row.Checklist