Skip to content

Commit 32c9daf

Browse files
authored
fix: bad JSON state leaving events disabled (#7501)
* fix: broken JSON state stopping event firing * chore: add unit test for events not breaking
1 parent f8a134c commit 32c9daf

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

core/serialization/blocks.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,13 @@ export function appendInternal(
399399
}
400400
eventUtils.disable();
401401

402-
const block = appendPrivate(state, workspace, {parentConnection, isShadow});
402+
let block;
403+
try {
404+
block = appendPrivate(state, workspace, {parentConnection, isShadow});
405+
} finally {
406+
eventUtils.enable();
407+
}
403408

404-
eventUtils.enable();
405409
if (eventUtils.isEnabled()) {
406410
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))(block));
407411
}

tests/mocha/jso_deserialization_test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@ suite('JSO Deserialization', function () {
2323
});
2424

2525
suite('Events', function () {
26+
test('bad JSON does not leave events disabled', function () {
27+
const state = {
28+
'blocks': {
29+
'blocks': [
30+
{
31+
'type': 'undefined_block',
32+
},
33+
],
34+
},
35+
};
36+
chai.assert.throws(() => {
37+
Blockly.serialization.workspaces.load(state, this.workspace);
38+
});
39+
chai.assert.isTrue(
40+
Blockly.Events.isEnabled(),
41+
'Expected events to be enabled',
42+
);
43+
});
44+
2645
suite('Finished loading', function () {
2746
test('Just var', function () {
2847
const state = {

0 commit comments

Comments
 (0)