Skip to content

StructuredText reports unstable intrinsic size in UIHostingConfiguration, causing cell overlap on first layout #52

Description

@mrmemes-eth

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

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

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

  1. Build a UICollectionView with UICollectionViewDiffableDataSource and UIHostingConfiguration cells. Apply snapshots with animatingDifferences: false.
  2. Each cell hosts a SwiftUI view containing:
    StructuredText(markdown: message.content)
        .foregroundStyle(Color.primary)
        .fixedSize(horizontal: false, vertical: true)
  3. Seed the data source with 5+ items of varied paragraph-length markdown.
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions