Description
When StructuredText is embedded in a UIHostingConfiguration inside a UICollectionView cell, the cell's intrinsic height changes between consecutive layout passes. On first layout (or scrolling into never-laid-out cells) all visible cells render at the same y-origin with overlapping text, then animate into their correct frames once the second measurement resolves.
Checklist
Expected behavior
StructuredText returns a stable intrinsic vertical size on the first layout pass, allowing it to be hosted in UIHostingConfiguration-backed collection-view cells without visible re-layout.
Actual behavior
Cells stack on top of each other on first appearance, then snap/animate to their correct positions once their final intrinsic heights resolve. This recurs every time the user scrolls into a region that has not been laid out before. swift-markdown-ui's Markdown view in the exact same hosting setup does not exhibit this — suggesting the issue is StructuredText-specific rather than a general UIHostingConfiguration issue. (Suspected cause: MarkdownUI emits a vertical stack of distinct SwiftUI views per block, so each child's intrinsic size is stable; StructuredText renders the whole document as one attributed-string-backed view whose ideal height resolves differently across passes — possibly tied to deferred work in the parser pipeline, but I haven't instrumented this.)
Steps to reproduce
- Build a
UICollectionView with UICollectionViewDiffableDataSource and UIHostingConfiguration cells. Apply snapshots with animatingDifferences: false.
- Each cell hosts a SwiftUI view containing:
StructuredText(markdown: message.content)
.foregroundStyle(Color.primary)
.fixedSize(horizontal: false, vertical: true)
- Seed the data source with 5+ items of varied paragraph-length markdown.
- Open the screen / scroll up into never-laid-out cells.
Observed: cells stack at the same y-origin on first paint, then animate into correct frames.
Things tried that did not fix it:
.animation(nil, value: message.content) on the StructuredText
.fixedSize(horizontal: false, vertical: true) on the StructuredText
Textual version information
0.3.1 (commit 5b06b81)
Destination operating system
iOS 26.3.1 (physical iPhone). Project deployment target is iOS 18.0.
Xcode version information
Xcode 26.3 (Build 17C529)
Swift Compiler version information
Apple Swift version 6.2.4 (swiftlang-6.2.4.1.4 clang-1700.6.4.2)
Target: arm64-apple-macosx26.0
Description
When
StructuredTextis embedded in aUIHostingConfigurationinside aUICollectionViewcell, the cell's intrinsic height changes between consecutive layout passes. On first layout (or scrolling into never-laid-out cells) all visible cells render at the same y-origin with overlapping text, then animate into their correct frames once the second measurement resolves.Checklist
mainbranch of this package.Expected behavior
StructuredTextreturns a stable intrinsic vertical size on the first layout pass, allowing it to be hosted inUIHostingConfiguration-backed collection-view cells without visible re-layout.Actual behavior
Cells stack on top of each other on first appearance, then snap/animate to their correct positions once their final intrinsic heights resolve. This recurs every time the user scrolls into a region that has not been laid out before.
swift-markdown-ui'sMarkdownview in the exact same hosting setup does not exhibit this — suggesting the issue isStructuredText-specific rather than a generalUIHostingConfigurationissue. (Suspected cause:MarkdownUIemits a vertical stack of distinct SwiftUI views per block, so each child's intrinsic size is stable;StructuredTextrenders the whole document as one attributed-string-backed view whose ideal height resolves differently across passes — possibly tied to deferred work in the parser pipeline, but I haven't instrumented this.)Steps to reproduce
UICollectionViewwithUICollectionViewDiffableDataSourceandUIHostingConfigurationcells. Apply snapshots withanimatingDifferences: false.Observed: cells stack at the same y-origin on first paint, then animate into correct frames.
Things tried that did not fix it:
.animation(nil, value: message.content)on theStructuredText.fixedSize(horizontal: false, vertical: true)on theStructuredTextTextual version information
0.3.1 (commit 5b06b81)
Destination operating system
iOS 26.3.1 (physical iPhone). Project deployment target is iOS 18.0.
Xcode version information
Xcode 26.3 (Build 17C529)
Swift Compiler version information