Skip to content

fix: replace AlignmentBarrierLayout with _FrameLayout to stop alignment cascade and message disappearing#24530

Merged
ashleeradka merged 1 commit into
mainfrom
devin/1743991988-fix-message-disappearing
Apr 9, 2026
Merged

fix: replace AlignmentBarrierLayout with _FrameLayout to stop alignment cascade and message disappearing#24530
ashleeradka merged 1 commit into
mainfrom
devin/1743991988-fix-message-disappearing

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot commented Apr 9, 2026

Summary

Removes AlignmentBarrierLayout — a custom Layout container that was wrapping the ScrollView to block alignment query cascades. While it successfully prevented the O(n) explicitAlignment hang, it disrupted SwiftUI's internal scroll infrastructure, causing messages to disappear on send, resize, scroll, and conversation switch (intermittently at first, then constantly after the LUM-811 streaming cache change increased body re-evaluation frequency).

Root cause of the hang was _FlexFrameLayout, not alignment queries reaching the LazyVStack directly. The fix replaces the two .frame(maxWidth:) modifiers (which create _FlexFrameLayout) with a single .frame(width:) (which creates _FrameLayout). _FrameLayout returns bounds.midX for alignment without querying children — the cascade stops here without needing any custom Layout in the view hierarchy.

Changes

  1. MessageListView.swift — Remove AlignmentBarrierLayout wrapper; unwrap ScrollView and all scroll modifiers back to the outer chain. Replace .frame(maxWidth: chatColumnMaxWidth).frame(maxWidth: .infinity) with .frame(width: containerWidth > 0 ? min(containerWidth, chatColumnMaxWidth) : chatColumnMaxWidth).
  2. AlignmentBarrierLayout.swift — Deleted (no other usages in the codebase).
  3. AGENTS.md — Replace barrier documentation with _FrameLayout vs _FlexFrameLayout guidance. Explicitly warns against custom Layout barriers near ScrollView.

Resulting modifier chain

ScrollView { scrollViewContent .background(ScrollObserver) }
  .scrollContentBackground(.hidden)
  .scrollDisabled(...)
  .defaultScrollAnchor(.bottom, for: .initialOffset)
  .scrollPosition($scrollPosition)
  .environment(\.suppressAutoScroll, ...)
  .onScrollPhaseChange { ... }
  .scrollIndicators(...)
  .id(conversationId)
  .frame(width: containerWidth > 0 ? min(containerWidth, chatColumnMaxWidth) : chatColumnMaxWidth)
  .overlay(alignment: .bottom) { ScrollToLatestOverlayView }
  .onAppear { handleAppear() }
  ... [remaining lifecycle modifiers]

No AlignmentBarrierLayout. No .frame(maxWidth:) on this path.

Review & Testing Checklist for Human

CI skips macOS builds — all items require local Xcode verification. Clean build recommended (Cmd+Shift+K, delete DerivedData).

  • Messages no longer disappear: Open a long conversation. Send a message, resize the window, switch conversations, scroll up and back down. Messages must remain visible throughout. This was the primary regression from the barrier approach.
  • Alignment hang is still fixed: Open a conversation with many tool calls. Resize the window repeatedly. Spindump should show near-zero explicitAlignment hits in the LazyVStack subtree. The _FrameLayout blocking the cascade is based on SwiftUI internals analysis (Apple doesn't document this explicitly) — the spindump is the definitive check.
  • Width, centering, and scroll area: The old .frame(maxWidth: 808).frame(maxWidth: .infinity) made the scroll area fill the full window width (scrollbar at window edge) with content centered at 808pt. The new .frame(width: computed) makes the scroll area exactly min(containerWidth, 808) wide. Verify: (a) chat column is centered and capped at 808pt on wide windows, (b) scrollbar position is acceptable, (c) fills correctly on narrow windows.
  • First-frame flash on narrow windows: With sidebar open (narrow chat area), reload the app. Check if there's a visible one-frame width jump as containerWidth goes from 0 → actual. The fallback is 808pt (MainWindowView.minWidth is 800, so this should be safe).
  • Thinking indicator dots: Verify the three-dot animation still works correctly within its bubble.

Notes

  • The 23 cell-level HStack+Spacer conversions from LUM-800 remain as defense-in-depth — they prevent any future .frame(maxWidth:) added above from cascading into cells.
  • The .overlay(alignment: .bottom) for ScrollToLatestOverlayView is safe: it applies to the result of .frame(width:), and _FrameLayout with a definite width does not query children for alignment.
  • The PodRuntimeTests CI failure (AppleContainersPodRuntime macOS 26.0 availability) is pre-existing and unrelated.

Link to Devin session: https://app.devin.ai/sessions/ef66aadc67724413b3b5ede76cf20ca9
Requested by: @ashleeradka


Open with Devin

…nt cascade

Remove AlignmentBarrierLayout — custom Layout containers between the outer
modifier chain and the ScrollView disrupt SwiftUI's internal scroll
infrastructure, causing intermittent cell materialization failures
(messages disappearing on send, resize, or scroll).

Replace .frame(maxWidth:).frame(maxWidth: .infinity) with a single
.frame(width: min(containerWidth, chatColumnMaxWidth)). _FrameLayout
returns bounds.midX for alignment without querying children, stopping
the O(n) explicitAlignment cascade at the source. The old _FlexFrameLayout
pattern cascaded alignment queries through the entire LazyVStack subtree
on every layout pass, causing 34-70s hangs.

- Remove AlignmentBarrierLayout.swift (no longer used)
- Restore pre-LUM-800 modifier chain order on ScrollView
- Update AGENTS.md anti-pattern rule

Co-Authored-By: ashlee@vellum.ai <ashlee@vellum.ai>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown
Contributor Author

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@ashleeradka ashleeradka merged commit 12ed92f into main Apr 9, 2026
7 checks passed
@ashleeradka ashleeradka deleted the devin/1743991988-fix-message-disappearing branch April 9, 2026 03:39
devin-ai-integration Bot added a commit that referenced this pull request Apr 9, 2026
The 6 .frame(maxWidth:) sites this PR changed are all siblings or
alternatives in the VStack, not ancestors of the LazyVStack. The
FlexFrame alignment cascade only propagates through ancestor nodes
to children — SwiftUI does not query alignment across siblings.
The dangerous ancestor-level FlexFrames were already fixed in PR
#24530. Reverting to avoid resize regressions (missing centering
layer, rigid .frame(width:) preventing fluid resize).

Co-Authored-By: ashlee@vellum.ai <ashlee@vellum.ai>
Jasonnnz pushed a commit that referenced this pull request Apr 10, 2026
Adds CI-enforced guard tests that scan Swift source files for three known
LazyVStack performance anti-patterns:

1. FlexFrameLayout (.frame(maxWidth:) / .frame(maxHeight:)) in cell hierarchy
2. motionVectors transitions (.transition(.move(edge:))) in cell hierarchy
3. withAnimation in scroll handlers (motionVectors cascade)

Prevents regression of fixes from PRs #24321, #24375, #24411, #24446,
#24530, #24570, #24589.

Part of #24613.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Jasonnnz added a commit that referenced this pull request Apr 10, 2026
* test: add SwiftUI performance guard tests for LazyVStack anti-patterns

Adds CI-enforced guard tests that scan Swift source files for three known
LazyVStack performance anti-patterns:

1. FlexFrameLayout (.frame(maxWidth:) / .frame(maxHeight:)) in cell hierarchy
2. motionVectors transitions (.transition(.move(edge:))) in cell hierarchy
3. withAnimation in scroll handlers (motionVectors cascade)

Prevents regression of fixes from PRs #24321, #24375, #24411, #24446,
#24530, #24570, #24589.

Part of #24613.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: add missing cell files to LAZY_VSTACK_CELL_FILES and remove PR references

Adds the 10 allowlisted file basenames to the cell hierarchy list so the
allowlist is actually consulted. Removes historical PR numbers from the
file header comment per AGENTS.md guidance.

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: use grep -E for portable ERE alternation in FlexFrame guard

BSD grep (macOS default) doesn't support \| in BRE mode. Switch to
grep -E with | for alternation so the guard works for local dev too.

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: add SubagentEventsReader to cell files and escape dots in transition grep

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Vellum Assistant <assistant@vellum.ai>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
devin-ai-integration Bot added a commit that referenced this pull request May 1, 2026
The blanket prohibition was based on AlignmentBarrierLayout (PR #24530)
which had specific scroll infrastructure issues. FixedWidthLayout is
functionally identical to _FrameLayout for width constraining — it just
blocks alignment cascades. The updated guidance distinguishes between
proven-safe FixedWidthLayout and untested new Layout types.

Co-Authored-By: ashlee@vellum.ai <ashlee@vellum.ai>
ashleeradka added a commit that referenced this pull request May 2, 2026
…nt cascade into BottomAlignedMinHeightLayout (#29212)

* fix(chat): replace _FrameLayout with FixedWidthLayout to stop alignment cascade into BottomAlignedMinHeightLayout

.frame(width:) on the ScrollView wrapper creates _FrameLayout whose
placeSubviews calls commonPlacement → ViewDimensions[guide], triggering
explicitAlignment on the entire child subtree. The cascade flows through
BottomAlignedMinHeightLayout.sizeThatFits, measuring the full ScrollView
content — causing 2s+ hangs (82 events, 10 users in Sentry MACOS-JG).

.fixedWidth() uses FixedWidthLayout (Layout protocol) which returns nil
from explicitAlignment, blocking both the _FrameLayout cascade and the
.overlay(alignment: .bottom) implicit ZStack alignment query.

Fixes VELLUM-ASSISTANT-MACOS-JG

Co-Authored-By: ashlee@vellum.ai <ashlee@vellum.ai>

* docs: refine AGENTS.md guidance on custom Layout outside ScrollView

The blanket prohibition was based on AlignmentBarrierLayout (PR #24530)
which had specific scroll infrastructure issues. FixedWidthLayout is
functionally identical to _FrameLayout for width constraining — it just
blocks alignment cascades. The updated guidance distinguishes between
proven-safe FixedWidthLayout and untested new Layout types.

Co-Authored-By: ashlee@vellum.ai <ashlee@vellum.ai>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant