Skip to content

fix(pagination): cache topLevelBlockElements + fix changeset language [review fixes for #434] - #436

Open
arthrod wants to merge 1 commit into
codex/pagination-atomic-measurefrom
claude/cool-tesla-t7Twt
Open

fix(pagination): cache topLevelBlockElements + fix changeset language [review fixes for #434]#436
arthrod wants to merge 1 commit into
codex/pagination-atomic-measurefrom
claude/cool-tesla-t7Twt

Conversation

@arthrod

@arthrod arthrod commented May 24, 2026

Copy link
Copy Markdown
Collaborator

Review fixes for #434 (two safe_auto findings from ce-review).

Changes

packages/pagination/src/react/domMeasure.ts

createDomMeasure was calling topLevelBlockElements(editable) inside the MeasureFn closure — once per block per recompute. For N blocks that's N querySelectorAll passes + N filter loops = O(N²) total DOM work. Hoisted the call to the outer createDomMeasure scope so it runs once per recompute.

.changeset/pagination-enabled-option.md

Changeset body used changelog-style language ("Add an enabled option"). AGENTS.md prohibits changelog-style; docs must document current state only. Rewrote to present-tense reference.

Residual findings (for #434 author)

See full review comment on #434. Key items requiring author decision:

  • enabled: boolean is non-optional in PaginationOptions — likely needs enabled?: boolean + semver bump reassessment
  • Template files bypass CI-control rule — needs explicit authorization in PR body
  • measureCache not cleared on re-enable after DOM-only changes while disabled
  • topLevelBlockElements refactor lacks unit test for the DnD-wrapper case

https://claude.ai/code/session_016Wodda9zsyQ9krUCZq6QxY


Generated by Claude Code

Summary by CodeRabbit

  • Documentation

    • Clarified pagination enabled option behavior: when disabled, pagination remains inactive with no page-break overlays rendered.
  • Performance

    • Optimized DOM element caching in pagination for improved measurement efficiency.

Review Change Stack

… changeset language

- domMeasure: hoist topLevelBlockElements() outside MeasureFn closure to
  avoid O(N²) DOM requery (was called once per block per recompute)
- changeset: rewrite from changelog-style to present-tense reference per
  docs standard (no 'Add an option'; use 'The option controls...')

https://claude.ai/code/session_016Wodda9zsyQ9krUCZq6QxY
@coderabbitai

coderabbitai Bot commented May 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e729f742-7873-4132-9713-9699fd065dae

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/cool-tesla-t7Twt

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

@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 changeset documentation for the pagination 'enabled' option and optimizes the createDomMeasure function by caching top-level block elements, which improves performance by avoiding redundant DOM queries. Feedback suggests that the current implementation's reliance on index-based mapping for DOM nodes may be fragile if the document contains top-level text nodes, and recommends using a more stable identifier for better robustness.


return (block) => {
const dom = topLevelBlockElements(editable)[block.path[0]];
const dom = blocks[block.path[0]];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The mapping blocks[block.path[0]] assumes that every top-level node in the Slate document is a Slate element with a corresponding DOM node found by topLevelBlockElements. If the document contains top-level text nodes or other non-element nodes, block.path[0] (the index in editor.children) will not align with the index in the filtered blocks array. While top-level text nodes are rare in many Slate configurations, using a more stable identifier (like a block ID) to find the DOM element would be more robust.

@arthrod
arthrod marked this pull request as ready for review May 25, 2026 02:05

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/pagination/src/react/domMeasure.ts (1)

94-100: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Consider clarifying the "Re-queries on each call" phrasing.

After the caching optimization, the JSDoc comment "Re-queries on each call so it reflects edits" could be misread to suggest the returned MeasureFn re-queries DOM per block. The blocks are now queried once per createDomMeasure invocation (which still reflects edits since it's called per recompute), not per block measurement.

📝 Suggested clarification
  * Build a {`@link` MeasureFn} that resolves the block's font + content width from
  * the live editable, then derives height from the number of lines pretext wraps
  * the block text to. Pretext — not the DOM box — owns the line count, so the
  * layout is line-accurate and the box's padding/margin don't perturb it.
- * Re-queries on each call so it reflects edits.
+ * Re-queries the DOM structure once per invocation to reflect edits; the
+ * returned function then performs per-block measurements via cached lookups.
  */
🤖 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/pagination/src/react/domMeasure.ts` around lines 94 - 100, The JSDoc
for the MeasureFn is misleading after the caching change: update the comment in
domMeasure.ts to clarify that DOM re-queries happen once per createDomMeasure()
invocation (which is called per recompute and thus reflects edits), not on every
individual MeasureFn call per block; reference the MeasureFn type and the
createDomMeasure function in the text so readers know where the caching occurs
and that measurements are reused for blocks within that invocation.
🤖 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.

Outside diff comments:
In `@packages/pagination/src/react/domMeasure.ts`:
- Around line 94-100: The JSDoc for the MeasureFn is misleading after the
caching change: update the comment in domMeasure.ts to clarify that DOM
re-queries happen once per createDomMeasure() invocation (which is called per
recompute and thus reflects edits), not on every individual MeasureFn call per
block; reference the MeasureFn type and the createDomMeasure function in the
text so readers know where the caching occurs and that measurements are reused
for blocks within that invocation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4bd587aa-d5d0-43ae-a65c-e766e3008bc0

📥 Commits

Reviewing files that changed from the base of the PR and between 7575081 and bb70d87.

📒 Files selected for processing (2)
  • .changeset/pagination-enabled-option.md
  • packages/pagination/src/react/domMeasure.ts

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.

2 participants