Do you want to request a feature or report a bug?
bug
What is the current behavior?
convertFromRaw is taking an argument (new/updated content) that includes an added entity of an embedded youtube link, but when i log out the result of convertFromRaw the entity isn't there. No errors.
**If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. You can use this jsfiddle to get started:
(your JS-fiddle is broken).
componentWillMount() {
const content = this.state.editorState.getCurrentContent();
const rawContent = convertToRaw(content);
const newContent = {
...rawContent,
entityMap: {
0: {
data: {
height: "auto",
src: "https://www.youtube.com/embed/5dsGWM5XGdg",
width: "auto",
},
mutability: "MUTABLE",
type: "EMBEDDED_LINK",
}
},
};
// 馃敿 this pulls in current content, converts to readable raw object of blocks & entities
// which we then push an entity into, with embedded youtube.
// we then convert *from* raw 馃斀
const updatedContentToPassBack = convertFromRaw(newContent);
// this should now be a useable contentState object to pass to EditorState
console.log('updatedContent: ', convertFromRaw(updatedContentToPassBack));
// ^^ converting it back to raw and there's no sign of my new entity there
// setting it state to render also does nothing 馃斀
this.setState({ editorState: EditorState.createWithContent(updatedContentToPassBack) });
}
What is the expected behavior?
embedded entity exists in draft object and is rendered.
Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js?
0.10.5 / Chrome / MacOS.
Same problem here. Can't export to raw -> save to DB and import from raw beacause the function fails when there are no entity maps
hi @Aid19801 have you found a solution for this? I'm having a similar problem where convertFromRaw ignores an entityMap with an image object in it
I've tried JSON.stringifying the convertToRaw object and then storing it in the DB, and then parsing it back when initializing the DraftJsEditor. But that didn't work. I also tried transforming the entityMap to an Array to store in my DB, and then converting it back into an object. I tried converting it to a map too. This didn't work either.
Solved it. The first problem was that my MongoDB database wasn't properly storing entity map. So I had to convert the entityMap to an array to store in my DB. Then, convert it back to an object.
The 2nd problem was that I was initializing my editorState without a decorator. So after I added my decorator, everything was good
EditorState.createWithContent(
convertFromRaw(convertRawToConvertable(serverBlog.draftJs)),
decorator
)
I am facing similar issue, @theweiweiway what is a decorator?
As @theweiweiway pointed out the MongoDB does not store empty objects. So in my case, I simply force MongoDB to store the empty object. If you are using mongoose as ORM then you can do this [method] (https://www.thetopsites.net/article/50767703.shtml). So this issue is not likely due to draftJS
Most helpful comment
hi @Aid19801 have you found a solution for this? I'm having a similar problem where convertFromRaw ignores an entityMap with an image object in it