Skip to content

fix: paginate oversized keep-next chains#155

Merged
jan-kubica merged 2 commits into
mainfrom
fix/parity-round-21
Jul 10, 2026
Merged

fix: paginate oversized keep-next chains#155
jan-kubica merged 2 commits into
mainfrom
fix/parity-round-21

Conversation

@jan-kubica

@jan-kubica jan-kubica commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • move an oversized keep-with-next chain to a fresh page when it cannot fit the current remainder
  • paginate the oversized chain naturally from that fresh page
  • retain the populated-page guard that prevents blank-page loops
  • add a focused integration regression and core patch changeset

Anonymized parity evidence

  • score: 0.2917 → 0.7562
  • pages: Word 12; Folio 11 → 12
  • pagination findings: 281 → 10
  • total findings: 464 → 206

Verification

  • 47 focused layout integration tests passed
  • bun audit reported no vulnerabilities
  • lint and typecheck intentionally delegated to CI

CC on behalf of @jan-kubica

Summary by CodeRabbit

  • Bug Fixes

    • Improved pagination for oversized “keep together” content chains.
    • Chains that cannot fit in the remaining space now move to the next page instead of being split unexpectedly.
    • Prevented unnecessary blank pages while preserving the intended sequence of connected content.
  • Tests

    • Added coverage for oversized keep-together chains to verify correct page placement during natural pagination.

@jan-kubica jan-kubica marked this pull request as ready for review July 10, 2026 09:01
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jan-kubica, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 44 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ba4f4879-d850-40ce-93e5-a87dfdc1476f

📥 Commits

Reviewing files that changed from the base of the PR and between d452800 and 87fce9d.

📒 Files selected for processing (2)
  • packages/core/src/__tests__/layout-pipeline.integration.test.ts
  • packages/core/src/layout-engine/index.ts
📝 Walkthrough

Walkthrough

Updates keepNext pagination so oversized chains move to a fresh page when the current page contains fragments. Adds an integration test and a patch changeset entry.

Changes

KeepNext chain pagination

Layer / File(s) Summary
Oversized chain page-break behavior
packages/core/src/layout-engine/index.ts, packages/core/src/__tests__/layout-pipeline.integration.test.ts, .changeset/oversized-keep-next-chain.md
The layout engine breaks before an oversized keepNext chain when the current page has fragments; integration coverage verifies the chain starts on the next page, and a patch changeset records the update.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing pagination for oversized keep-next chains.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/parity-round-21

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the layout engine to handle oversized 'keep-with-next' chains by moving them to a fresh page before natural pagination. The reviewer identified that the current implementation using 'paginator.forcePageBreak()' is not column-aware and suggested using the existing 'paginator.ensureFits(chainHeight)' abstraction instead, which handles column flow correctly and allows for code simplification.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread packages/core/src/layout-engine/index.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/core/src/__tests__/layout-pipeline.integration.test.ts (1)

551-567: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider asserting the chain paginates across multiple pages.

The test name promises "paginating it naturally" but only verifies the chain moved to page 1. Since 6 blocks × 200 = 1200 likely exceeds a single page, adding an assertion that the chain spans pages 1+ would verify the natural-pagination half of the behavior.

♻️ Optional: add multi-page assertion
     expect(chainStartPage).toBe(1);
     expect(layout.pages[0]?.fragments.map(({ blockId }) => blockId)).toEqual([0]);
+
+    // The oversized chain should paginate naturally across multiple pages.
+    const chainPageCount = layout.pages.filter((page) =>
+      page.fragments.some(({ blockId }) => blockId >= 1 && blockId <= 6),
+    ).length;
+    expect(chainPageCount).toBeGreaterThan(1);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/src/__tests__/layout-pipeline.integration.test.ts` around lines
551 - 567, Add an assertion to the test “moves an oversized keepNext chain
before paginating it naturally” verifying that the chain’s fragments appear
across multiple pages, specifically on page 1 and at least one later page. Keep
the existing assertions for the chain’s starting page and the filler-only first
page.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/core/src/__tests__/layout-pipeline.integration.test.ts`:
- Around line 551-567: Add an assertion to the test “moves an oversized keepNext
chain before paginating it naturally” verifying that the chain’s fragments
appear across multiple pages, specifically on page 1 and at least one later
page. Keep the existing assertions for the chain’s starting page and the
filler-only first page.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f3eddf1c-9e5f-4ce3-8a10-f197cc53da42

📥 Commits

Reviewing files that changed from the base of the PR and between 95aca77 and d452800.

📒 Files selected for processing (3)
  • .changeset/oversized-keep-next-chain.md
  • packages/core/src/__tests__/layout-pipeline.integration.test.ts
  • packages/core/src/layout-engine/index.ts

@jan-kubica

Copy link
Copy Markdown
Contributor Author

Updated the regression to assert the oversized chain spans more than one page, addressing the CodeRabbit nitpick. CC on behalf of @jan-kubica

@jan-kubica jan-kubica merged commit 8a3888c into main Jul 10, 2026
8 checks passed
@jan-kubica jan-kubica deleted the fix/parity-round-21 branch July 10, 2026 09:51
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant