Skip to content

fix(core): stop schema.extend() mutating the shared default specs - #3039

Merged
nperez0111 merged 1 commit into
mainfrom
fix/schema-extend-mutates-default-specs
Sep 1, 2026
Merged

fix(core): stop schema.extend() mutating the shared default specs#3039
nperez0111 merged 1 commit into
mainfrom
fix/schema-extend-mutates-default-specs

Conversation

@YousefED

@YousefED YousefED commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2968

Symptom

In the playground, open the multi-column example, then the basic example: you can now drop blocks side by side in the basic editor (no vertical drop indicator is shown, but columns get created).

Root cause

Global state mutation, not editor cleanup. CustomBlockNoteSchema.extend() merged the added specs into the existing spec objects:

Object.assign(this.opts.blockSpecs, opts.blockSpecs);

BlockNoteSchema.create() with no arguments passes the module-level defaultBlockSpecs / defaultInlineContentSpecs / defaultStyleSpecs by reference, so withMultiColumn(BlockNoteSchema.create()) wrote column and columnList into the shared defaults. Every editor created afterwards without an explicit schema (e.g. the basic example's useCreateBlockNote()) then inherited:

  • the column / columnList node types, and
  • the editor extensions those block specs register (multiColumnDropHandler, columnResize), which the ExtensionManager collects from schema.blockSpecs.

It did not inherit the dropCursor: multiColumnDropCursor editor option, which is why the drop works but no side indicator is shown.

This affects more than the playground: BlockNoteSchema.create().extend({...}) is the pattern the docs recommend, and withPageBreak uses it too, so any app that creates one extended editor and later a default-schema editor got a polluted default schema.

Fix

extend() merges into fresh objects and reassigns this.opts instead of writing into the inputs. This also stops it from mutating a caller-owned spec object passed to create({ blockSpecs }). The schema instance's builder semantics are unchanged (extend still mutates and returns this).

Tests

New packages/core/src/schema/schema.test.ts with three cases — the shared defaults stay untouched, a caller-owned spec object stays untouched, and the end-to-end symptom (a default-schema editor created after an extended one has neither the block nor the extension it registers). All three fail on those assertions before the fix and pass after.

Verification

  • Core unit suite (766) and xl-multi-column unit suite (82) pass; vp lint --type-aware and vp fmt clean.
  • Reproduced the real path in the source-aliased playground dev server (multi-column → "Basic Setup" via the sidebar, i.e. SPA navigation): without the fix the basic editor's schema has ["column","columnList"] and tiptap extensions ["multiColumnDropHandler","columnResize","column","columnList"]; with the fix all are empty.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed schema extensions so custom blocks, inline content, and styles no longer modify shared default configurations.
    • Prevented custom blocks and editor extensions from unexpectedly appearing in other editors using the default schema.
  • Tests

    • Added coverage confirming schema extensions remain isolated and do not mutate provided specifications or later default-schema editors.

`CustomBlockNoteSchema.extend()` merged the added specs into the existing
spec objects with `Object.assign`. `BlockNoteSchema.create()` passes the
module-level `defaultBlockSpecs` / `defaultInlineContentSpecs` /
`defaultStyleSpecs` by reference, so `BlockNoteSchema.create().extend(...)`
(the documented pattern, used by `withMultiColumn` and `withPageBreak`)
wrote the added specs into the shared defaults. Every editor created
afterwards without an explicit schema silently inherited the extra block
types and the editor extensions they register - e.g. in the playground,
visiting the multi-column example and then the basic example let you drop
blocks side by side in the basic editor (no drop indicator, since the
`dropCursor` option isn't part of the schema).

`extend()` now merges into fresh objects and reassigns `this.opts`, which
also stops it from mutating a caller-owned spec object passed to `create`.

Adds a regression test covering the shared defaults, caller-owned spec
objects, and the end-to-end symptom (a default-schema editor created after
an extended one must have neither the block nor its extension).
@vercel

vercel Bot commented Sep 1, 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 1, 2026 12:33pm UTC
blocknote-website Ready Ready Preview Sep 1, 2026 12:33pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: e4c94fd8-6c14-4a99-8d0f-2f6f4e6a7c54

📥 Commits

Reviewing files that changed from the base of the PR and between f0d80ae and 6611557.

📒 Files selected for processing (2)
  • packages/core/src/schema/schema.test.ts
  • packages/core/src/schema/schema.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

BlockNoteSchema.extend() now merges specifications without mutating shared objects. New tests verify default schemas, explicit specification objects, and editor extensions remain isolated.

Changes

Schema extension isolation

Layer / File(s) Summary
Fresh schema specification merges
packages/core/src/schema/schema.ts
extend() creates fresh block, inline-content, and style specification objects instead of mutating existing objects.
Schema and editor isolation tests
packages/core/src/schema/schema.test.ts
Tests verify custom specifications appear only in extended schemas, source specifications remain unchanged, and registered editor extensions do not leak into later default-schema editors.

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

Merge Risk: ⚪ Minimal · up to 66115

The PR prevents schema extensions from mutating shared defaults or caller-owned specifications, eliminating order-dependent behavior between editors. No actionable merge-blocking risk remains after normal checks and review.

Poem

A rabbit found a schema wide,
With fresh new maps kept side by side.
Custom blocks hop where they belong,
Default editors stay clear and strong.
No borrowed state can trail along.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: preventing schema.extend() from mutating shared default specifications.
Description check ✅ Passed The description is detailed and covers the symptom, root cause, fix, impact, regression tests, and verification. It does not use every template heading or include a completed checklist, but it provide…
Linked Issues check ✅ Passed The changes address issue [#2968] by preventing global schema mutations, stopping multi-column behavior from leaking into later playground examples, and adding regression coverage for the reported sce…
Out of Scope Changes check ✅ Passed The changes are limited to the schema merge behavior and focused regression tests. No unrelated code changes are identified.
Full details: Description check

Explanation

The description is detailed and covers the symptom, root cause, fix, impact, regression tests, and verification. It does not use every template heading or include a completed checklist, but it provides the required technical context.

Full details: Linked Issues check

Explanation

The changes address issue [#2968] by preventing global schema mutations, stopping multi-column behavior from leaking into later playground examples, and adding regression coverage for the reported scenario.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/schema-extend-mutates-default-specs

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 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/ariakit@3039

@blocknote/code-block

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/code-block@3039

@blocknote/core

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/core@3039

@blocknote/diagram-block

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/diagram-block@3039

@blocknote/mantine

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/mantine@3039

@blocknote/math-block

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/math-block@3039

@blocknote/react

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/react@3039

@blocknote/server-util

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/server-util@3039

@blocknote/shadcn

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/shadcn@3039

@blocknote/xl-ai

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-ai@3039

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-docx-exporter@3039

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-email-exporter@3039

@blocknote/xl-multi-column

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-multi-column@3039

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-odt-exporter@3039

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-pdf-exporter@3039

@blocknote/xl-typst-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-typst-exporter@3039

commit: 6611557

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-09-01 13:05 UTC

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

I had found this separately on the nested blocks branch, but let's go with this first

@nperez0111
nperez0111 merged commit ab4015c into main Sep 1, 2026
31 checks passed
@nperez0111
nperez0111 deleted the fix/schema-extend-mutates-default-specs branch September 1, 2026 13:05
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.

Playground editor state between examples leaks over

2 participants