chore(blocks.render): mutex for onchange added to the blocks.render() #2449
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.
TL;DR
onChange won't be called on
blocks.render()
. Like in 2.27 and before.Context
#2430 introduced a few updates:
onChange
mutex was removed from Renderer sinceRenderer.render()
became awaitable and we just enable Modification Observer after initial rendering:editor.js/src/components/core.ts
Lines 54 to 62 in be0d33c
So the
onChange
became enabled in theblocks.render()
APIonChange
with removed blockseditor.js/src/components/modules/blockManager.ts
Lines 858 to 867 in be0d33c
Both of these changes are correct and actual. The initial render does not call
onChange
(because a document is not changed), but theblocks.render()
calls it with removed and added blocks (because an existing document is cleared).Problem
During the RC test we got feedback that the
blocks.render()
method is expected to be mutation-free.Solution
I thought about it and found three solutions:
render()
methodrender()
After all, I've decided to mute onChange inside the render method for two pros:
Cons:
onChange
call, but some are not. I think that we need to redesign the API at all, based on the new Document Model in 3.0.Also
blocks.clear()
now returns a promise. So we can call it before render as a workaround if we want to receive "block-removed" events