Conversation
Blocks.replace(), Blocks.insert(..., replace = true) and Blocks.removeAll() dropped their Block without ever calling Block.destroy(), so the Tool instance kept its listeners and mutation observer alive. Every blocks.update(), every conversion and every replace-on-empty-block leaked one Tool. Destroy the Block where it actually leaves the collection instead of in one caller: Blocks.remove() now owns the cleanup, which also covers BlockManager.removeAllBlocks(), and the duplicate destroy() call in BlockManager.removeBlock() is dropped so a Tool is still destroyed exactly once.
Minhal128
requested review from
TatianaFomina,
gohabereg,
ilyamore88 and
neSpecc
as code owners
September 24, 2026 14:33
neSpecc
reviewed
Sep 24, 2026
neSpecc
left a comment
Member
There was a problem hiding this comment.
Seems ok. Please, cover all block removing cases with tests.
Also, increment a patch version and drop a line in a changelog
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3029
The problem
Blockhas adestroy()that tears down its listeners, its mutation observer and the Tool instance. But three of the paths where a Block leaves the collection never called it:Blocks.replace()blocks.update()Blocks.insert(..., replace = true)Blocks.removeAll()blocks.clear()In each case the Block is detached from the DOM and dropped from the array while its Tool keeps its input listeners and
MutationObserveralive. A document that is converted or updated a few hundred times accumulates one live Tool per operation.Not what the issue says
The issue reports that
destroy()is "never called anywhere". That part is not accurate, and it matters:BlockManager.removeBlock()(blockManager.ts) already callsblock.destroy()right afterthis._blocks.remove(index). Adding adestroy()insideBlocks.remove()on top of that would have called every Tool'sdestroy()twice.The change
Rather than patching each caller, the cleanup now lives where a Block actually leaves the collection:
Blocks.remove()destroys the Block it splices out — which also fixesBlockManager.removeAllBlocks(), since that loops over_blocks.remove(index)block.destroy()inBlockManager.removeBlock()is dropped, so a Tool is still destroyed exactly onceBlocks.replace(),Blocks.insert(..., replace = true)andBlocks.removeAll()destroy the Block they dropdestroy()is always called after theREMOVEDhook, so a Tool still observes removal before being torn down.I checked that
Blocks.move()andBlocks.swap()reuse the Block instance without going throughremove(), so moving a Block does not destroy it.Verification
Added a Cypress spec asserting that
blocks.update()destroys the Tool of the Block it replaces. Ran the suite on a fork in both directions:expected onDestroy to have been called exactly once, but it was never called(3 attempts)So the spec genuinely reproduces the leak and the fix closes it, and nothing else in the suite regressed.