Skip to content

fix(blocks): trigger onChange for insertMany - #3050

Merged
neSpecc merged 1 commit into
codex-team:nextfrom
ZainnQureshii:fix/insertmany-onchange
Nov 16, 2026
Merged

neSpecc merged 1 commit into
codex-team:nextfrom
ZainnQureshii:fix/insertmany-onchange

Conversation

@ZainnQureshii

@ZainnQureshii ZainnQureshii commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2874

blocks.insertMany() inserted the blocks but never reported them, so onChange stayed silent while insert, delete and move all fire it. BlockManager.insertMany now emits a block-added event for each inserted block, with its own index, and the observer batches them into one onChange call as it does for other mutations.

The renderer also loads the initial document through BlockManager.insertMany, so core.ts now calls ModificationsObserver.disable() right before the initial render and keeps the existing enable() after it, the same way blocks.render() and the read-only toggle already wrap their re-renders. ModificationsObserver keeps its default (disabled = false), so loading a document stays silent without changing the observer's starting state.

Changes:

  • src/components/modules/blockManager.ts: emit block-added for each block in insertMany.
  • src/components/core.ts: disable the observer explicitly around the initial render.
  • test/cypress/tests/onchange.cy.ts: regression test for one batched call with both inserted blocks, their ids and indices 1 and 2, and no call on initialization.
  • docs/CHANGELOG.md: one Fix line under 2.32.0.

How it was checked:

  • Rebased on current next; yarn lint (0 errors) and yarn build pass.
  • yarn test:e2e --spec test/cypress/tests/onchange.cy.ts: 31 of 31 pass.
  • With the disable() call removed from core.ts, the same spec fails 25 of 31, since every editor created with initial blocks then fires onChange on load, so the "should not be called on initialization" assertions cover the explicit disable.
  • The new insertMany test fails on next and passes with the change.

Prepared with AI assistance (Claude Code) and reviewed with GitHub Copilot.

🤖 Generated with Claude Code

Copilot AI 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.

🟢 Approved

No active review issues remain for the change adding insertMany() mutation notifications while keeping initialization silent.

No open issues 🎉

What changed in this PR

Fixes #2874 by making blocks.insertMany() report mutations through onChange, consistent with other block operations, while keeping initial document loading silent.

Changes:

  • Emit a block-added event with the correct index for each inserted block.
  • Start mutation notifications disabled until initialization completes.
  • Add regression coverage for batched events, block IDs and indices, and silent initialization; document the fix.
File Description
test/​cypress/​tests/​onchange.cy.ts Tests batched insertion events and silent initialization.
src/​components/​modules/​modificationsObserver.ts Starts change notifications disabled.
src/​components/​modules/​blockManager.ts Emits indexed block-added events for bulk insertions.
docs/​CHANGELOG.md Records the insertMany() notification fix.

Review effort: Balanced

Emit a block-added mutation for each block inserted by BlockManager.insertMany and keep the modifications observer disabled until the initial render finishes, so loading a document stays silent.

Fixes codex-team#2874

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ZainnQureshii
ZainnQureshii force-pushed the fix/insertmany-onchange branch from 9c1ba74 to 861a3fa Compare November 16, 2026 10:24
@neSpecc
neSpecc enabled auto-merge (squash) November 16, 2026 10:29
@neSpecc
neSpecc merged commit 93f8c5c into codex-team:next Nov 16, 2026
4 checks passed
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.

Inconsistent Behavior: insertMany Does Not Trigger Mutation Events in Editor.js

3 participants