Skip to content

Fix forced breaks in flex rows#2743

Open
moreaki wants to merge 1 commit into
Kozea:mainfrom
moreaki:fix-flex-row-breaks
Open

Fix forced breaks in flex rows#2743
moreaki wants to merge 1 commit into
Kozea:mainfrom
moreaki:fix-flex-row-breaks

Conversation

@moreaki
Copy link
Copy Markdown
Contributor

@moreaki moreaki commented Apr 22, 2026

Summary

This PR adds a narrow forced-break path for row flex containers. When a row flex item requests a forced page break before or after another item, the flex line is split at that item boundary and the remaining items resume on the next page.

Part of #2400.

Root Cause

Flex layout already delegates final child layout to the normal block layout machinery, but it did not inspect break opportunities between flex items. As a result, break-before: page and break-after: page on row flex items were ignored, even though block and table layout already honor the same break values between sibling boxes.

Changes

  • Reuse block_level_page_break and force_page_break to detect forced page breaks between row flex items.
  • Split the current flex line at the forced break boundary.
  • Resume layout from the first item after the forced break on the next page.
  • Add coverage for break-before: page, break-after: page, and a wrapped-row boundary.

Known Remaining Scope

This intentionally handles a small, reviewable slice of flex breaks. Remaining work includes:

  • break-before on the first flex item, which needs parent/container-level coordination to avoid pointless blank pages.
  • Full left / right / recto / verso behavior and page-name selection tests.
  • avoid values, which require finding earlier/later legal flex-line break opportunities.
  • Column flex direction interactions without regressing existing column fragmentation behavior.
  • break-inside: avoid for row flex items, especially when one item fragments and another should remain unbroken.
  • Interactions between forced sibling breaks and already-fragmented flex items.
  • Nested table/grid/flex children whose own break signals need to compose with flex-line breaks.

Validation

  • venv/bin/python -m pytest tests/layout/test_flex.py
  • venv/bin/python -m pytest tests/layout
  • venv/bin/python -m ruff check weasyprint/layout/flex.py tests/layout/test_flex.py

@moreaki moreaki mentioned this pull request Apr 22, 2026
11 tasks
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