From bb7e887d9de43bc71107d5e8830ee74bb421e5e4 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Mon, 18 Sep 2023 19:26:06 +0000 Subject: [PATCH 1/2] fix: broken JSON state stopping event firing --- core/serialization/blocks.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/serialization/blocks.ts b/core/serialization/blocks.ts index 053d523a2ff..e53f30944a0 100644 --- a/core/serialization/blocks.ts +++ b/core/serialization/blocks.ts @@ -399,9 +399,13 @@ export function appendInternal( } eventUtils.disable(); - const block = appendPrivate(state, workspace, {parentConnection, isShadow}); + let block; + try { + block = appendPrivate(state, workspace, {parentConnection, isShadow}); + } finally { + eventUtils.enable(); + } - eventUtils.enable(); if (eventUtils.isEnabled()) { eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))(block)); } From 4d98a60341dbd0e5b745a3f384e168be7755be6a Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Mon, 18 Sep 2023 19:46:21 +0000 Subject: [PATCH 2/2] chore: add unit test for events not breaking --- tests/mocha/jso_deserialization_test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/mocha/jso_deserialization_test.js b/tests/mocha/jso_deserialization_test.js index fa6590cb7dd..d58e208fbe0 100644 --- a/tests/mocha/jso_deserialization_test.js +++ b/tests/mocha/jso_deserialization_test.js @@ -23,6 +23,25 @@ suite('JSO Deserialization', function () { }); suite('Events', function () { + test('bad JSON does not leave events disabled', function () { + const state = { + 'blocks': { + 'blocks': [ + { + 'type': 'undefined_block', + }, + ], + }, + }; + chai.assert.throws(() => { + Blockly.serialization.workspaces.load(state, this.workspace); + }); + chai.assert.isTrue( + Blockly.Events.isEnabled(), + 'Expected events to be enabled', + ); + }); + suite('Finished loading', function () { test('Just var', function () { const state = {