html-to-draftjs icon indicating copy to clipboard operation
html-to-draftjs copied to clipboard

html-to-draftjs.js:2 Uncaught TypeError: Cannot read property 'type' of undefined

Open mayconbeserra opened this issue 6 years ago • 17 comments

@jpuri I'm still getting the same issue:

image

My package.json

"html-to-draftjs": "^0.1.0-beta11" "react-draft-wysiwyg": "^1.10.7"

As I need this feature soon, is there any workaround?

mayconbeserra avatar Jul 30 '17 10:07 mayconbeserra

@mayconbeserra : can you plz share the HTML which are are trying to convert to editor content.

jpuri avatar Jul 30 '17 10:07 jpuri

Hi @jpuri it's a blank text. the RichEditor.Render log is printing what I'm receiving.

Should it be <p></p>?

mayconbeserra avatar Jul 30 '17 10:07 mayconbeserra

@jpuri I added <p></p> when the content is Empty Or Null, and then I started getting another error:

image

mayconbeserra avatar Jul 30 '17 10:07 mayconbeserra

@mayconbeserra : which version of lib are you using ?

jpuri avatar Jul 30 '17 10:07 jpuri

@jpuri here image

mayconbeserra avatar Jul 30 '17 10:07 mayconbeserra

for rendering, I'm doing as suggested in the readme:

render() { console.log('RichEditor:render', this.props.content);

const blocksFromHtml = htmlToDraft(this.props.content || '<p></p>');
const { contentBlocks, entityMap } = blocksFromHtml.contentBlocks;
const contentState = ContentState.createFromBlockArray(contentBlocks, entityMap);
const editorState = EditorState.createWithContent(contentState);`

And I'm using editorState variable to link to the component

mayconbeserra avatar Jul 30 '17 10:07 mayconbeserra

@jpuri the error above, I managed to solve with the example from that guy: https://github.com/facebook/draft-js/issues/809

However, when I started typing and pause, and type again, the new text is added at the beginning of the RichEditor, which is wrong. It should be added at the end of the editor.

This only happens when I'm converting from Html to ContentState and binding it to the Editor.

Any thoughts about that?

mayconbeserra avatar Jul 30 '17 11:07 mayconbeserra

@mayconbeserra : it works for m here if I use

: https://github.com/jpuri/html-to-draftjs/blob/master/src/index.js#L21

Are you marking editor controlled component ?

jpuri avatar Jul 30 '17 11:07 jpuri

yes, it's a controlled component

mayconbeserra avatar Jul 30 '17 11:07 mayconbeserra

Are you converting each time from html, I will not suggest that - it will slow down editor.

Also [email protected] has fix for above issue with input html is empty.

jpuri avatar Jul 30 '17 12:07 jpuri

That error has occurred with example code in README.md. Try to use that code:

const {contentBlocks, entityMap} = htmlToDraft(this.props.content);
const contentState = ContentState.createFromBlockArray(contentBlocks, entityMap);
const editorState = EditorState.createWithContent(contentState);

It fixed in #26

pyatyispyatil avatar Aug 07 '17 20:08 pyatyispyatil

@jpuri It can not show the font-size when i use the html-to-draft, but the attribute of color is showing correctly.

abbycoco avatar Dec 04 '17 10:12 abbycoco

@jpuri help, help, help.

abbycoco avatar Dec 04 '17 10:12 abbycoco

重复刷新当前页面出现的问题 TypeError: Cannot read property 'trim' of undefined 有没有解决办法 feb5f8902cfe0e6cb7bb63dbfd19334dd039e72799c1db0be5e719bc60e6bd0dQzpcVXNlcnNc6ZmI5rC46b6ZXEFwcERhdGFcUm9hbWluZ1xEaW5nVGFsa1wyMzk3OTIxMDkxX3YyXEltYWdlRmlsZXNcMTYyOTQ0NTI3ODY1M18zQTY1RjIwMi00NzVELTQzYzQtQjk0Mi1COTEzQTQ5NzQzQ0MucG5n

xiaopya avatar Aug 20 '21 07:08 xiaopya

e2c412116af52dbeddae728743bd0808fbc5d86febd6404c4dc0ea537ea6fb12QzpcVXNlcnNc6ZmI5rC46b6ZXEFwcERhdGFcUm9hbWluZ1xEaW5nVGFsa1wyMzk3OTIxMDkxX3YyXEltYWdlRmlsZXNcMTYyOTQ0NTg1MzY4MV84NzYxN0JFNy1FRjUyLTRhNmEtOUY4MS1EOTMzNDJDOTI5MzIucG5n

xiaopya avatar Aug 20 '21 07:08 xiaopya

重复刷新当前页面出现的问题 TypeError: Cannot read property 'trim' of undefined 有没有解决办法 feb5f8902cfe0e6cb7bb63dbfd19334dd039e72799c1db0be5e719bc60e6bd0dQzpcVXNlcnNc6ZmI5rC46b6ZXEFwcERhdGFcUm9hbWluZ1xEaW5nVGFsa1wyMzk3OTIxMDkxX3YyXEltYWdlRmlsZXNcMTYyOTQ0NTI3ODY1M18zQTY1RjIwMi00NzVELTQzYzQtQjk0Mi1COTEzQTQ5NzQzQ0MucG5n

I have the same 'trim' problem...

codigoisaac avatar Mar 22 '22 23:03 codigoisaac

@codigoisaac 问题解决了吗?我也遇到同样的问题

2629832248 avatar Oct 14 '22 15:10 2629832248