Skip to content

Fix pageBreakBefore with unbreakable blocks#2927

Open
rstrand wants to merge 1 commit intobpampuch:masterfrom
Xentrans:fix/pagebreakbefore-unbreakable-blocks
Open

Fix pageBreakBefore with unbreakable blocks#2927
rstrand wants to merge 1 commit intobpampuch:masterfrom
Xentrans:fix/pagebreakbefore-unbreakable-blocks

Conversation

@rstrand
Copy link

@rstrand rstrand commented Mar 17, 2026

I was trying to implement the documented orphaned-children pattern to prevent headings from being stranded at the bottom of a page:

pageBreakBefore: function(currentNode, nodeContainer) {
  return currentNode.headlineLevel === 1 &&
         nodeContainer.getFollowingNodesOnPage().length === 0;
}

This didn't work when the content following the heading was inside an unbreakable: true block. The callback's getFollowingNodesOnPage() was returning the unbreakable block's nodes as still on the same page as the heading, even though they had moved to the next page. I also found that header/footer nodes were appearing in the results, further preventing the length === 0 check from ever being true.

I tracked the cause down to a few issues:

  • _node back-references, which addFragment() uses to update positions when blocks move pages, were only set on lines with tocItem or id. I changed this to set _node on all text lines and added tracking for image, SVG, canvas, QR, and attachment nodes.

  • Nodes from dynamic headers and footers were being pushed into linearNodeList, which contaminated getFollowingNodesOnPage() and the other pageBreakBefore helpers with irrelevant nodes. I added a flag to suppress this during addDynamicRepeatable() processing.

  • I also noticed that attachments inside unbreakable blocks were being silently dropped because addFragment() had no case for the 'attachment' item type.

This PR addresses these and adds relevant test cases.

pageBreakBefore helpers like getFollowingNodesOnPage() returned
incorrect results when unbreakable blocks moved to a new page,
breaking the documented orphaned-children pattern. Node positions
were not updated because _node back-references were only set on
lines with tocItem or id.

* always set _node on text lines and add tracking for image/SVG/canvas/QR/attachment nodes
* exclude header/footer nodes from linearNodeList
* fix attachments silently dropped inside unbreakable blocks
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