-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
convertFromHTML with empty string returns results that can't be used with createFromBlockArray #157
Comments
I run into the same problem. It's even true for empty tags like import { EditorState, ContentState, convertFromHTML } from 'draft-js';
function createContentStateFromHtml(html) {
const { contentBlocks, entityMap } = convertFromHTML(html);
return ContentState.createFromBlockArray(contentBlocks, entityMap);
}
const content = createContentStateFromHtml('<p></p>');
const editor = EditorState.createWithContent(content);
// throws TypeError: contentState.getBlockMap(...).first(...) is undefined
// for now I am using this:
const editor = content.getBlockMap().size
? EditorState.createWithContent(content)
: EditorState.createEmpty(); So there is a difference between const { contentBlocks, entityMap } = convertFromHTML('');
// ContentState.createFromText('').blockMap.size === 1
// ContentState.createFromBlockArray(contentBlocks, entityMap).blockMap.size === 0 |
Similar to the above, and also somehow unexpected: import { ContentState, convertFromHTML } from 'draft-js';
const { contentBlocks, entityMap } = convertFromHTML('<p></p>');
const content = ContentState.createFromBlockArray(contentBlocks, entityMap);
const hasText = content.hasText();
// throws TypeError: blockMap.first(...) is undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have this:
TypeError: contentState.getBlockMap(...).first(...) is undefined
createWithContent
./node_modules/draft-js/lib/EditorState.js:55
52 | };
53 |
54 | EditorState.createWithContent = function createWithContent(contentState, decorator) {
getEditorBaseState
./components/RecipePage.tsx:164
161 | },
162 | ]);
163 |
The text was updated successfully, but these errors were encountered: