Skip to content

Commit 01fc2e5

Browse files
committed
fix: error initializing empty editor
(“Cannot read property 'contentBlocks' of null”)
1 parent 1bd9750 commit 01fc2e5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

angular-draft-js/draft-js.component.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ export class DraftHtmlBase extends DraftBase {
5252

5353
const blocksFromHTML = convertFromHTML(html);
5454

55-
if (!blocksFromHTML) { return emptyState; }
55+
let contentBlocks, entityMap;
5656

57-
const state = ContentState.createFromBlockArray(
58-
blocksFromHTML.contentBlocks,
59-
blocksFromHTML.entityMap,
60-
);
57+
try {
58+
contentBlocks = blocksFromHTML.contentBlocks;
59+
entityMap = blocksFromHTML.entityMap;
60+
} catch (e) {
61+
return emptyState;
62+
}
63+
64+
const state = ContentState.createFromBlockArray(contentBlocks, entityMap);
6165
return EditorState.createWithContent(state, this.editorProps.decorator);
6266
}
6367
}

0 commit comments

Comments
 (0)