fix(macos): stop zero-width measurements from poisoning chat cell caches#26316
Merged
Conversation
During the first LazyVStack layout pass, MessageListLayoutMetrics deliberately reports bubbleMaxWidth = 0 until GeometryReader resolves the chat column width. That zero flowed unchecked into MarkdownSegmentView.effectiveMaxWidth and VSelectableTextView.measureSize(maxWidth: 0), where ensureLayout returned a usedRect with height 0. Before the recent sizeThatFits-caching commit (#26170), the degenerate result self-healed on the next body pass; with the new caches, (0,0) was persisted at the attributedString + 0 + 4 key and the MarkdownSegmentView NSCache entry keyed on effectiveMaxWidth = 0, collapsing the cell and stacking every visible assistant message body at the same y. Two small, orthogonal guards: - VSelectableTextView.measureSize refuses maxWidth <= 0 or empty strings with an early .zero return (no cache write), and only writes non-zero heights into measurementSizeCache. - MarkdownSegmentView.resolveSelectableRunMeasurementResult skips the measuredTextCache insertion when size.height == 0. Both keep the perf wins from #26170 and #26242 (no revert). Adds a regression test that measures at maxContentWidth: 0 and asserts no cache poisoning. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Review focus / risk notes
|
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
MessageListLayoutMetrics(clients/macos/vellum-assistant/Features/Chat/MessageListLayoutMetrics.swift:14-32) reportsbubbleMaxWidth = 0untilGeometryReaderresolves the chat column width. That zero cascades throughMarkdownSegmentView.effectiveMaxWidth(line 404 uses??which only fires onnil, not on0) intoVSelectableTextView.measureSize(maxWidth: 0), whereensureLayoutreturns ausedRectwithheight == 0..frame(width: 0, height: 0)applied bySelectableRunViewcollapses the cell — all visible assistant messages stack at the same y.VSelectableTextView.measurementSizeCacheandMarkdownSegmentView.measuredTextCache) persisted the(0,0)result at the 0-width cache key, so the cell stayed collapsed.Changes
VSelectableTextView.measureSizeguardsmaxWidth > 0 && attributedString.length > 0and returns.zerowithout writing the cache. Also only persists non-zero heights inmeasurementSizeCache.MarkdownSegmentView.resolveSelectableRunMeasurementResultaddssize.height > 0 &&to themeasuredTextCacheinsertion guard.testZeroWidthReturnsZeroSizeWithoutPoisoningCachesregression test.Test plan
clients/macos/build.sh), open a long multi-message conversation, confirm each assistant body renders at a distinct y with no overlap.xcodebuild testforMarkdownSegmentViewTests— new regression test passes, existing tests unaffected.🤖 Generated with Claude Code