Skip to content

Commit 1bd9750

Browse files
committed
fix: errors in console on empty editor updates
Now sanitizing input in DraftHtmlBase.stateFromHTML
1 parent 940bda2 commit 1bd9750

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class DraftBase {
3333
export class DraftHtmlBase extends DraftBase {
3434
@Input()
3535
set html(html: string) {
36-
const state: EditorState = html ? this.stateFromHTML(html) : EditorState.createEmpty();
36+
const state: EditorState = this.stateFromHTML(html);
3737
this.editorProps = Object.assign({}, this.editorProps, { editorState: state });
3838
}
3939

@@ -45,8 +45,15 @@ export class DraftHtmlBase extends DraftBase {
4545
});
4646
}
4747

48-
stateFromHTML(html: string) {
48+
stateFromHTML(html: string): EditorState {
49+
const emptyState = EditorState.createEmpty();
50+
51+
if (!html) { return emptyState; }
52+
4953
const blocksFromHTML = convertFromHTML(html);
54+
55+
if (!blocksFromHTML) { return emptyState; }
56+
5057
const state = ContentState.createFromBlockArray(
5158
blocksFromHTML.contentBlocks,
5259
blocksFromHTML.entityMap,

0 commit comments

Comments
 (0)