Skip to content

fix(core): unwrap a dissolving container in place - #3104

Open
YousefED wants to merge 1 commit into
container-blocks/unifiedfrom
container-blocks/repair-caret
Open

YousefED wants to merge 1 commit into
container-blocks/unifiedfrom
container-blocks/repair-caret

Conversation

@YousefED

@YousefED YousefED commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Builds on #3059.

The fix

When a container drops below min, fixContainer rebuilt it from its surviving child with tr.replaceWith — a delete plus an insert, so a caret inside that child collapsed out of it and landed in a different block entirely.

fixColumnList used a ReplaceAroundStep here before the rewrite, so this is restoring prior behaviour rather than new work. The step leaves the surviving content untouched in the document, so positions inside it map through.

It covers the single-survivor case, which is the only one any container in the repo can reach (columnList and every fixture are min: 2). Several survivors are not one contiguous range once an emptied child sits between them, so that path still rebuilds; it takes a min of 3 or more to reach and is noted in a comment.

Tests

  • 3 caret tests — one per unwrap shape (pair, one level; grid/gridCell, two) and one for the real column case in removeBlocks. All three fail without the fix, with the caret landing in the wrong block.
  • Additionally, added 4 crash tests for column layout edges that had no coverage: Delete at the end of a layout that is the document's last block, Delete in an empty first column, Delete at the end of a trailing empty block, and Backspace at the start of a column after an empty one. Each throws on main (Attempted to get blockContainer node at position 23, RangeError: Position 7 out of range) and passes here. They assert invariants — no throw, valid document, no text lost — so they read the same on both branches.

Verified behaviour-neutral for columns: a differential over 14,800 sculpted columnList states (2–4 columns × 5 per-column shapes × 4 surroundings × caret in each column) comparing document, selection, validity and throw behaviour against main's fixColumnList shows 0 differences. Without the fix the same matrix shows 248.

🤖 Generated with Claude Code

When a container drops below `min`, `fixContainer` rebuilt it from its
surviving child with `tr.replaceWith`, so a caret inside that child
collapsed out of it. `fixColumnList` used a `ReplaceAroundStep` here
before the rewrite; this restores it for the single-survivor case, which
is the only one any container in the repo can reach.

Also covers the column layout edges that used to throw out of the
keydown handler and had no tests.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
blocknote Ready Ready Preview Sep 21, 2026 6:02pm UTC
blocknote-website Ready Ready Preview Sep 21, 2026 6:02pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: ce10aa45-587f-4a90-ba76-dd2d04d13801

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:

  • 🔍 Trigger review

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.

@pkg-pr-new

pkg-pr-new Bot commented Sep 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/@blocknote/ariakit@3104

@blocknote/code-block

npm i https://pkg.pr.new/@blocknote/code-block@3104

@blocknote/core

npm i https://pkg.pr.new/@blocknote/core@3104

@blocknote/diagram-block

npm i https://pkg.pr.new/@blocknote/diagram-block@3104

@blocknote/mantine

npm i https://pkg.pr.new/@blocknote/mantine@3104

@blocknote/math-block

npm i https://pkg.pr.new/@blocknote/math-block@3104

@blocknote/react

npm i https://pkg.pr.new/@blocknote/react@3104

@blocknote/server-util

npm i https://pkg.pr.new/@blocknote/server-util@3104

@blocknote/shadcn

npm i https://pkg.pr.new/@blocknote/shadcn@3104

@blocknote/xl-ai

npm i https://pkg.pr.new/@blocknote/xl-ai@3104

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/@blocknote/xl-docx-exporter@3104

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/@blocknote/xl-email-exporter@3104

@blocknote/xl-multi-column

npm i https://pkg.pr.new/@blocknote/xl-multi-column@3104

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/@blocknote/xl-odt-exporter@3104

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/@blocknote/xl-pdf-exporter@3104

@blocknote/xl-typst-exporter

npm i https://pkg.pr.new/@blocknote/xl-typst-exporter@3104

commit: e696f37

@github-actions

github-actions Bot commented Sep 21, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://TypeCellOS.github.io/BlockNote/pr-preview/pr-3104/

Built to branch gh-pages at 2026-09-21 18:13 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@nperez0111 nperez0111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yep, that's cleaner in terms of ops

This branch was successfully deployed

2 active deployments
Preview – blocknote-website e696f375 Deployed Sep 21, 2026 by vercel[bot]
Preview – blocknote e696f375 Deployed Sep 21, 2026 by vercel[bot]
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