Skip to content

Commit 134f691

Browse files
hata6502t.hatagohabereg
authored
Bugfix/fix modification observer disable (#1340)
* Enable modification observer when onChange callback throws an error * Build * Update src/components/modules/modificationsObserver.ts Co-authored-by: George Berezhnoy <gohabereg@users.noreply.github.com> * Update CHANGELOG Co-authored-by: t.hata <hata@impact-blue.co.jp> Co-authored-by: George Berezhnoy <gohabereg@users.noreply.github.com>
1 parent 1245a53 commit 134f691

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

dist/editor.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- `Fix` - blocks.getBlockByIndex() API method now returns void for indexes out of range [#1270](https://github.com/codex-team/editor.js/issues/1270)
2222
- `Fix` - Fixed the `onChange` callback issue. This method didn't be called for native inputs before some contentedtable element changed [#843](https://github.com/codex-team/editor.js/issues/843)
2323
- `Fix` - Fixed the `Tab` key behavior when the caret is not set inside contenteditable element, but the block is selected [#1302](https://github.com/codex-team/editor.js/issues/1302).
24+
- `Fix` - Fixed the `onChange` callback issue. This method didn't be called after the callback throws an exception [#1339](https://github.com/codex-team/editor.js/issues/1339)
2425

2526
### 2.18
2627

src/components/modules/modificationsObserver.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class ModificationsObserver extends Module {
2828
/**
2929
* Allows to temporary disable mutations handling
3030
*/
31-
private disabled: boolean;
31+
private disabled = false;
3232

3333
/**
3434
* Used to prevent several mutation callback execution
@@ -37,7 +37,10 @@ export default class ModificationsObserver extends Module {
3737
*/
3838
private mutationDebouncer = _.debounce(() => {
3939
this.updateNativeInputs();
40-
this.config.onChange(this.Editor.API.methods);
40+
41+
if (typeof this.config.onChange === 'function') {
42+
this.config.onChange(this.Editor.API.methods);
43+
}
4144
}, ModificationsObserver.DebounceTimer);
4245

4346
/**
@@ -127,7 +130,7 @@ export default class ModificationsObserver extends Module {
127130
* @param {MutationRecord[]} mutationList - list of mutations
128131
* @param {MutationObserver} observer - observer instance
129132
*/
130-
private mutationHandler(mutationList: MutationRecord[], observer): void {
133+
private mutationHandler(mutationList: MutationRecord[], observer: MutationObserver): void {
131134
/**
132135
* Skip mutations in stealth mode
133136
*/

src/components/modules/saver.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ export default class Saver extends Module {
3636
*/
3737
ModificationsObserver.disable();
3838

39-
blocks.forEach((block: Block) => {
40-
chainData.push(this.getSavedData(block));
41-
});
42-
43-
const extractedData = await Promise.all(chainData);
44-
const sanitizedData = await Sanitizer.sanitizeBlocks(extractedData);
39+
try {
40+
blocks.forEach((block: Block) => {
41+
chainData.push(this.getSavedData(block));
42+
});
4543

46-
ModificationsObserver.enable();
44+
const extractedData = await Promise.all(chainData);
45+
const sanitizedData = await Sanitizer.sanitizeBlocks(extractedData);
4746

48-
return this.makeOutput(sanitizedData);
47+
return this.makeOutput(sanitizedData);
48+
} finally {
49+
ModificationsObserver.enable();
50+
}
4951
}
5052

5153
/**

0 commit comments

Comments
 (0)