Skip to content

Line of a breakable block is lost when a float is deferred to the next page #8890

Open

Description

@ManuelLerchner

Description

A line of text disappears when a breakable block splits onto a page whose space is reduced by a deferred float.

#set page(width: 60pt, height: 100pt)
#v(30pt)
#figure(rect(height: 60pt), placement: auto)
#block[A \ B \ C \ D \ E]

Page 1 shows A, B, C. Page 2 shows the float and E. D is missing in PNG, SVG and PDF output.

If the lost line contains the start of a link, PDF export fails instead:

error: internal error: expected link ancestor in logical tree (occurred at crates/typst-pdf/src/link.rs:107:10)

That's how I ran into it in a larger document. The error is the same as in #7777 and #8608, but the cause is different, and it still happens on main after #8778.

The cause seems to be that a breakable block is laid out again for every page it spills onto, and the earlier pages don't always come out the same way (the comment in MultiSpill::layout in flow/collect.rs mentions this). Here widow prevention (distribute.rs:350-360) moves D to the next page only if D and E fit there. On page 1 the next page is assumed to be empty, so D moves. Once page 2 is laid out with the float, D and E no longer fit, so D stays on page 1 in that layout. Page 1 uses the first layout and page 2 uses the second, and D ends up on neither.

I have a local patch that detects when the new layout changes an already emitted frame and skips the region instead. Happy to open a PR if that approach sounds acceptable.

Operating system

macOS

Typst version

  • I am using the latest version of Typst

Activity

  1. ManuelLerchner commented on Sep 24, 2026

    @ManuelLerchner
    Author

    A proof-of-concept patch is on my fork, written with AI help. Not a PR, just in case it helps with the diagnosis: ManuelLerchner/typst@main...fix-lost-line-breakable-block

    Image
  2. added
    bug
    layout
    on Sep 28, 2026
  3. laurmaedje commented on Sep 28, 2026

    @laurmaedje
    Member

    Same underlying issue as #8487, but I've closed the other one since it has more irrelevant tangents and is less to the point.

    I was aware of the potential for this issue when writing the original code but misjudged the likelihood of it practically happening. The fix proposed by AI is interesting. It is an extremely hacky band-aid, but at least feasible without rewriting large swaths of the layout engine. I will think about what to do here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buglayout

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions