fix: improve performance of connecting blocks (#6876)

* fix: early return from updateDisabled if it is noop

* chore: trigger connect and disconnect before hiding

* chore: remove disconnectInternal

* fix: skip setting parent when disconnecting before connecting

* chore: fixup docs

* chore: remove erroneous test

* fix: add delay to context menu callback.

Improve INP by allowing the browser to do a paint (closing the context
menu) before we trigger callbacks. This improves the user experience
for expensive callbacks (e.g. collapsing, or updating disabled).

* fix: rendering bug

When disconnecting the last block in the stack, the block would not be
rerendered correctly (the top-start corner would not be reshaped)

* fix: connecting bug

The order for applying connections was changed so that connections were
applied and then the insertion marker was hidden. This caused an error
because hiding the insertion marker expected there to be a child block
when there was not.

* chore: remove setParent param from public API

* chore: tsdoc
This commit is contained in:
Beka Westberg
2023-03-16 13:40:33 -07:00
committed by GitHub
parent 4efd2042f9
commit c2919c51bd
6 changed files with 92 additions and 124 deletions

View File

@@ -117,11 +117,15 @@ function populate_(
if (option.enabled) {
const actionHandler = function() {
hide();
// If .scope does not exist on the option, then the callback will not
// be expecting a scope parameter, so there should be no problems. Just
// assume it is a ContextMenuOption and we'll pass undefined if it's
// not.
option.callback((option as ContextMenuOption).scope);
requestAnimationFrame(() => {
setTimeout(() => {
// If .scope does not exist on the option, then the callback
// will not be expecting a scope parameter, so there should be
// no problems. Just assume it is a ContextMenuOption and we'll
// pass undefined if it's not.
option.callback((option as ContextMenuOption).scope);
}, 0);
});
};
menuItem.onAction(actionHandler, {});
}