mergeEntityData modifies editorState in place
See original GitHub issueDo you want to request a feature or report a bug? Bug report
What is the current behavior?
/*
* > editorState.getCurrentContent().getEntity(entityKey).getData()
* <- {name: 'John', id: '3'}
*/
const contentState = editorState.getCurrentContent()
const newContentState = contentState.mergeEntityData(entityKey, {name: 'Pete'})
/*
* > editorState.getCurrentContent().getEntity(entityKey).getData()
* Should still return {name: 'John', id: '3'}, but actually returns {name: 'Pete', id: '3'}
*/
This being the case, we cannot push the new contentState onto editorState because
editorState.getCurrentContent() === contentState
returns true
and EditorState.push()
exits with the base case.
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: https://jsfiddle.net/stopachka/m6z0xn4r/. Just try it out in the console as above.
What is the expected behavior? These model objects should be immutable, no? Regardless, we should be able to push a contentState with updated entity data.
Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js? master branch, Google Chrome, macOS Sierra
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (1 by maintainers)
Top GitHub Comments
As of v0.10 it is still as I wrote. You can see here that
ContentState
is delegating to the old internals ofDraftEntity
. I’ve got it working without ever creating a newEditorState
. As I have it working, your example would be@krishnagopinath many thanks!