fix(pagination): margin-aware packing + continuous-overlay polish (dogfood fixes)#421
fix(pagination): margin-aware packing + continuous-overlay polish (dogfood fixes)#421arthrod wants to merge 1 commit into
Conversation
…-001..004) - 001: compose packs by flow height (text + DOM box spacing via flowHeightPx), so page count + breaks match real DOM flow (demo: 3→4 pages, correct for 2965px content). heightPx/lineCount stay text-only for line mapping. - 003: overlay shows 'Page N of M' + a 'Page 1 of M' marker. - 004: labels moved to the left margin gutter so they stay on-screen when a narrow viewport overflows the page width. - 002: recompute runs in a layout effect (pre-paint) instead of post-paint rAF; content→lines gap ~604ms→~308ms (residual is editor hydration). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@coderabbitai review very carefully and fix |
|
@gemini review very carefully and fix |
|
@Kilo review very carefully and fix |
There was a problem hiding this comment.
Code Review
This pull request introduces margin-aware page packing by incorporating DOM box spacing (margins, padding, and borders) into layout calculations via a new flowHeightPx property. It also enhances the pagination overlay by displaying 'Page N of M' labels, adding a marker for the first page, and moving labels to the left margin gutter for better visibility on narrow viewports. Additionally, the layout recomputation was moved to a layout effect to ensure advisory lines appear simultaneously with content. Feedback was provided regarding the line-height resolution in the overlay, suggesting a more robust fallback than 0 when the computed style is 'normal' to prevent positioning errors.
| const lineHeight = | ||
| Number.parseFloat(getComputedStyle(el).lineHeight) || 0; |
There was a problem hiding this comment.
The current line height resolution falls back to 0 if the computed line-height is normal (which parseFloat returns as NaN). This will cause incorrect positioning of advisory lines if lineStart > 0 (e.g., in future line-split modes). It's better to fall back to a heuristic like fontSize * 1.5 or a constant, similar to the resolveLineHeight logic used in domMeasure.ts.
const style = getComputedStyle(el);
const lineHeight =
Number.parseFloat(style.lineHeight) ||
Number.parseFloat(style.fontSize) * 1.5 ||
20;
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chainI'll start by fetching the PR details and diff to review the changes carefully. 🏁 Script executed: Length of output: 20067 Good — I have the full diff. Let me pull more context on the key files before writing up the review. 🏁 Script executed: Length of output: 22881
🔴 Bug —
|
| Area | Status |
|---|---|
flowOf() helper and overflow / keep-with-next packing logic |
Correct |
verticalBoxSpacing margin-collapse over-count |
Acknowledged and safe (conservative direction) |
flowHeightPx only set when boxSpacingPx > 0 (clean fallback) |
Correct |
useIsomorphicLayoutEffect SSR guard |
Standard pattern ✓ |
labelStyle extracted to module scope (no inline object churn) |
Good refactor |
topOf() helper de-duplicated from break rendering |
Clean ✓ |
New compose.spec cases cover both branches of flowOf |
Good coverage |
| Changeset entry present and accurate | ✓ |
Changes needed
- Fix
heightPx: flow→heightPx: b.heightPxincompose.ts - Fix
breaks.length === 0early-return guard inPaginationPlugin.tsxto allow single-page "Page 1 of 1" label - Add explanatory comment on the intentional missing dep-array for
useIsomorphicLayoutEffect
The requested changes have been implemented and a pull request has been created: View PR
Fixes the four issues from the
/dogfoodpass on/dev/pagination2. Stacked on #418.ISSUE-001 (medium) — break lines drifted past the true page boundary
Compose now packs pages by a block's flow height = pretext text height + the DOM box spacing (margins/padding/borders) the measurer supplies as a new
flowHeightPx(falls back to text height when absent).heightPx/lineCountstay text-only, so line-level mapping is untouched.compose.speccases — packs byflowHeightPxwhen present, falls back when absent.ISSUE-003 (low) — no Page 1 / no total
Labels now read
Page N of Mwith aPage 1 of Mmarker at the top.ISSUE-004 (low) — labels off-screen on narrow viewports
Labels moved to the left margin gutter. Verified at a 600px viewport: all labels on-screen (left:49, right:112) vs off-screen before.
ISSUE-002 (low) — ~600ms load flash
Recompute runs in an isomorphic layout effect (pre-paint) instead of post-paint
requestAnimationFrame. Content→lines gap ~604ms → ~308ms; the residual is the editor's hydration time (SSR content is on screen before the client can measure the DOM — inherent to a client-measured overlay).Verification
@platejs/paginationbuild 8/8, typecheck 8/8, 49 tests pass (47 + 2 new), biome clean.localhost:3000/dev/pagination2(default + 600px viewports); editing/selection still native (pointer-events:none); no console errors.🤖 Generated with Claude Code