fix(app): reject stale timeline range indexes#33488
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a TanStack Virtual edge case in the session message timeline where “resize-pinned” indexes can become stale after the timeline projection shrinks, causing getVirtualItems() to return undefined entries and crash consumers that expect the contract to hold.
Changes:
- Introduces
filterVirtualIndexes()to discard out-of-range virtualizer indexes against the currentrange.count. - Applies the filtering inside the timeline’s custom
rangeExtractorto prevent invalid indexes from reaching TanStack Virtual. - Adds a regression test covering the stale pinned-index scenario when the row count shrinks.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/app/src/pages/session/timeline/virtual-items.ts | Adds a small helper to filter virtualizer indexes to [0, count). |
| packages/app/src/pages/session/timeline/virtual-items.test.ts | Adds a regression test ensuring stale pinned indexes are removed after shrink. |
| packages/app/src/pages/session/timeline/message-timeline.tsx | Uses the helper in rangeExtractor to prevent invalid indexes from propagating into getVirtualItems(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rangeExtractorto indexes in[0, range.count)new Map(...)crash path with the installed patched Solid adapterDeterministic root cause
Large row resizes capture visible DOM indexes in
resizePinnedIndexesand retain them for two animation frames. The timeline projection can shrink before those frames expire. The custom range extractor previously merged the stale pinned indexes without validating them against the newrange.count.TanStack Virtual trusts custom range extractors.
getVirtualItems()indexes directly into the current measurement array, so an out-of-range index addsundefined. The Solid adapter reconciles that value into its keyed store, leaving a sparse array. The timeline then preserves the hole through.map(...), andnew Map(...)throwsTypeError: Iterator value undefined is not an entry object.The browser-condition regression uses the real adapter:
getVirtualItems()contains only index 0.new Map(items.map(...))conversion does not throw.With
filterVirtualIndexeschanged to return its input unchanged, this test deterministically fails at step 4 withTypeError.The fix rejects invalid indexes at the custom range producer rather than masking missing items at the
Mapconsumer.CI timeout stabilization
The first CI run also exposed two unrelated
packages/opencode/test/session/prompt.test.tstests whose 3-second limits were below their observed live-clock runtimes. Both useit.instance, which runs with the live Effect clock, plus real temporary Git repositories, HTTP, and subprocess work; the shell case also executessleep 0.2.Using the pinned Bun 1.3.14 locally, both failed 5/5 at 3 seconds and completed cleanly at 10 seconds. Their timeout limits are raised to 10 seconds without changing test behavior.
Verification
bun install --frozen-lockfilebun run test:virtualizer: 3 passedbun typecheckfrompackages/appgit diff --check upstream/dev...HEAD