Line of a breakable block is lost when a float is deferred to the next page
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
Source: typst/typst