Preserve controlled inner blocks on RESET_BLOCKS#61524
Conversation
|
Size Change: -21 B (0%) Total Size: 1.74 MB
ℹ️ View Unchanged
|
What guarantees that the clientIDs of the new blocks are still "controlled"? |
First I assume that the If the new version of the block doesn't want to be controlled, it will signal that by not mounting In short, the controlled state is now controlled solely by Until now not everything was under |
That makes sense, in my understanding this PR was removing the "cleanup" from useBlockSync while useBlockSync is the only place that knows for sure whether a block is controlled or not. As for the clientId, for me we can't really assume that a clientId refers to the same block after you call RESET_BLOCKS but this is fine as long as useBlockSync is responsible for cleaning things up. |
Yes: even if
The old implementation didn't have this inconsistent "new block with old controlled children" state. Instead, if both the old and new block were of the same type and both wanted to be controlled (canonical example of such a reset is an undo that changes only other blocks), the block became briefly uncontrolled, with uncontrolled inner blocks. |
|
Just noting that #75458 was merged into trunk. |
|
Let's close this, if there's anything missing from what landed in @jsnajdr let us know. |
Experiment inspired by #61480.
RESET_BLOCKSaction destroys thecontrolledInnerBlocksstate and also doesn't carry over the info about controlled inner blocks.useBlockSyncthen needs special code to quickly recover the controlled state and to set the controller inner blocks again.This PR attempts to improve the
RESET_BLOCKSaction so that the controlled blocks state is carried over. That means:state.controlledInnerBlocksis preserved, and we continue to know that a block with certainclientIdshould be controlled.state.attributes,state.byClientId, ...) for controlled inner blocks is preserved. Previously only the state for the new blocks and their uncontrolled children (innerBlocks) was part of the new state, the rest was forgotten.state.ordercontains the controlled blocks, it's not reset to uncontrolled. These are still instate.tree, and will be written tostate.orderif the block switches to uncontrolled mode.Let's see how this fares with the e2e tests.
Currently the
RESET_BLOCKSreducer carries over too much info: it keeps everything that was in the previous state, and only adds info fromaction.blocks. This is harmless, but inefficient. If the experiment proves viable, I'll improve the code to carry over only the old controlled blocks + new blocks fromaction.blocks.