question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mergeEntityData modifies editorState in place

See original GitHub issue

Do 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:closed
  • Created 7 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
cbothnercommented, Apr 9, 2017

As of v0.10 it is still as I wrote. You can see here that ContentState is delegating to the old internals of DraftEntity. I’ve got it working without ever creating a new EditorState. As I have it working, your example would be

const { path, filename } = data;
contentState = editorState.getCurrentContent();
contentState.replaceEntityData(entityKey, { src: path, alt: filename });
this.onChange(editorState);
1reaction
Fi1osofcommented, Jul 10, 2017

@krishnagopinath many thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Draft-JS - Entity component doesn't re-render when data ...
Draft-JS - Entity component doesn't re-render when data changes ; EditorState } from ; import { getSelectionText, getSelectionEntity } from ...
Read more >
ContentState - Draft.js
An EditorState object maintains undo and redo stacks comprised of ... is used to place the selection range in the appropriate position.
Read more >
module draft-js function - GitHub Pages
insertAtomicBlock (editorState, entityKey, character) ... mergeEntityData (key, toMerge); function draft-js. ... If an * override is in place, use it.
Read more >
https://unpkg.com/@types/draft-js@0.10.45/index.d.ts
The `editorState` prop defines the entire state of the editor, ... that modify content or * selection state and update the editor state...
Read more >
Getting started with draft.js - React Rocket
To quote from the draft-js docs, EditorState is an immutable ... with a new editorState instance, that contains the changes made to it, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found