Skip to content

Commit

Permalink
fix: dynamic blocks erroring on workspace dispose (#2271)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega authored Mar 26, 2024
1 parent 9a7b924 commit ac5086d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
16 changes: 9 additions & 7 deletions plugins/block-dynamic-connection/src/dynamic_if.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ const DYNAMIC_IF_MIXIN = {
* @returns XML storage element.
*/
mutationToDom(this: DynamicIfBlock): Element | null {
// If we call finalizeConnections here without disabling events, we get into
// an event loop.
Blockly.Events.disable();
this.finalizeConnections();
if (this instanceof Blockly.BlockSvg) this.initSvg();
Blockly.Events.enable();
if (!this.isDeadOrDying()) {
// If we call finalizeConnections here without disabling events, we get into
// an event loop.
Blockly.Events.disable();
this.finalizeConnections();
if (this instanceof Blockly.BlockSvg) this.initSvg();
Blockly.Events.enable();
}

if (!this.elseifCount && !this.elseCount) return null;

Expand Down Expand Up @@ -162,7 +164,7 @@ const DYNAMIC_IF_MIXIN = {
* @returns The state of this block, ie the else if count and else state.
*/
saveExtraState: function (this: DynamicIfBlock): IfExtraState | null {
if (!this.isCorrectlyFormatted()) {
if (!this.isDeadOrDying() && !this.isCorrectlyFormatted()) {
// If we call finalizeConnections here without disabling events, we get into
// an event loop.
Blockly.Events.disable();
Expand Down
16 changes: 9 additions & 7 deletions plugins/block-dynamic-connection/src/dynamic_list_create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ const DYNAMIC_LIST_CREATE_MIXIN = {
* @returns XML storage element.
*/
mutationToDom(this: DynamicListCreateBlock): Element {
// If we call finalizeConnections here without disabling events, we get into
// an event loop.
Blockly.Events.disable();
this.finalizeConnections();
if (this instanceof Blockly.BlockSvg) this.initSvg();
Blockly.Events.enable();
if (!this.isDeadOrDying()) {
// If we call finalizeConnections here without disabling events, we get into
// an event loop.
Blockly.Events.disable();
this.finalizeConnections();
if (this instanceof Blockly.BlockSvg) this.initSvg();
Blockly.Events.enable();
}

const container = Blockly.utils.xml.createElement('mutation');
container.setAttribute('items', `${this.itemCount}`);
Expand Down Expand Up @@ -112,7 +114,7 @@ const DYNAMIC_LIST_CREATE_MIXIN = {
* @returns The state of this block, ie the item count.
*/
saveExtraState: function (this: DynamicListCreateBlock): {itemCount: number} {
if (!this.isCorrectlyFormatted()) {
if (!this.isDeadOrDying() && !this.isCorrectlyFormatted()) {
// If we call finalizeConnections here without disabling events, we get
// into an event loop.
Blockly.Events.disable();
Expand Down
16 changes: 9 additions & 7 deletions plugins/block-dynamic-connection/src/dynamic_text_join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ const DYNAMIC_TEXT_JOIN_MIXIN = {
* @returns XML storage element.
*/
mutationToDom(this: DynamicTextJoinBlock): Element {
// If we call finalizeConnections here without disabling events, we get into
// an event loop.
Blockly.Events.disable();
this.finalizeConnections();
if (this instanceof Blockly.BlockSvg) this.initSvg();
Blockly.Events.enable();
if (!this.isDeadOrDying()) {
// If we call finalizeConnections here without disabling events, we get into
// an event loop.
Blockly.Events.disable();
this.finalizeConnections();
if (this instanceof Blockly.BlockSvg) this.initSvg();
Blockly.Events.enable();
}

const container = Blockly.utils.xml.createElement('mutation');
container.setAttribute('items', `${this.itemCount}`);
Expand Down Expand Up @@ -108,7 +110,7 @@ const DYNAMIC_TEXT_JOIN_MIXIN = {
* @returns The state of this block, ie the item count.
*/
saveExtraState: function (this: DynamicTextJoinBlock): {itemCount: number} {
if (!this.isCorrectlyFormatted()) {
if (!this.isDeadOrDying() && !this.isCorrectlyFormatted()) {
// If we call finalizeConnections here without disabling events, we get into
// an event loop.
Blockly.Events.disable();
Expand Down

0 comments on commit ac5086d

Please sign in to comment.