Skip to content

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

Open
ZainnQureshii wants to merge 1 commit into
codex-team:nextfrom
ZainnQureshii:fix/insertmany-onchange
Open

ZainnQureshii wants to merge 1 commit into
codex-team:nextfrom
ZainnQureshii:fix/insertmany-onchange

Conversation

@ZainnQureshii

Copy link
Copy Markdown

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 ModificationsObserver now starts disabled (disabled = true) and is switched on by core.ts after the first render, as blocks.render() and the read-only toggle already do around their re-renders. Loading a document therefore stays silent, and the existing "should not be called on initialization" tests still pass.

Changes:

  • src/components/modules/blockManager.ts: emit block-added for each block in insertMany.
  • src/components/modules/modificationsObserver.ts: start disabled until the editor is ready.
  • 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 (Node 18.20.1 from .nvmrc):

  • yarn lint and yarn build pass.
  • The new test fails on next and passes with the change.
  • yarn test:e2e: 30 specs, 283 tests passed and none failed before the local Electron tab crashed on ui/toolbox.cy.ts; the remaining 10 specs were rerun on their own: 86 passed, 1 failed. The failure is utils/flipper.cy.ts "should prevent plugins event handlers from being called while keyboard navigation" (Cannot set properties of undefined (setting 'selected') in selectBlock), and it fails the same way on next without this change.

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

🤖 Generated with Claude Code

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>

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

/**
* Flag shows onChange event is disabled
*/
private disabled = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this seems unexpected. I'd suggest explicitly call disable/enable on initial render.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

make sure it is covered by tests

This branch has not been deployed

No deployments
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