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.

updating entities fail to trigger render

See original GitHub issue

This seems to be a bug.

When updating the contentState of the Editor it is my understanding the child entity Components should be updated with new contentState prop. This does not seem to be happening.

The specific situation is that I am updating contentState with a new result from contentState.mergeEntityData and subsequent Editor.push.

In the following fiddle, I expect the activate and deactivate buttons to update the contentState, thus re-rendering the entity’s TestComponent which should resort in the toggling of a blue or yellow background. You can verify the {active} data triggers the background change by editing the initial rawData and verify that the contentState is updating with the “Log State” button.

https://jsfiddle.net/steckel/h9gd6bm0/

I am testing using Chrome 56.0.2924.87 and draft-js 0.10.0.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
noahlemencommented, Mar 1, 2017

I agree, this is certainly annoying behavior!

The workaround that currently seems to be advised is to use EditorState.forceSelection to force an update. In your fiddle, pressing a button and then clicking to change selection does cause {active} to update.

For example, using forceSelection as workaround might look like:

_handleActiveEntityClick = () => {
  const entityKey = "1";
  const contentState = this.state.editorState.getCurrentContent();
  const entity = contentState.getEntity(entityKey);
  const newContentState = contentState.replaceEntityData(entityKey, {active: true});
    
  const editorState = EditorState.push(this.state.editorState, newContentState, "activate-entity-data");
  const selection = editorState.getSelection();
    
  this.setState({editorState: EditorState.forceSelection(editorState, selection)});
}

_handleDeactiveEntityClick = () => {
  const entityKey = "1";
  const contentState = this.state.editorState.getCurrentContent();
  const entity = contentState.getEntity(entityKey);
  const newContentState = contentState.replaceEntityData(entityKey, {active: false});

  const editorState = EditorState.push(this.state.editorState, newContentState, "deactivate-entity-data");
  const selection = editorState.getSelection();
    
  this.setState({editorState: EditorState.forceSelection(editorState, selection)});
}

Anyway, I agree that this is undesirable and would ideally be handled better…

3reactions
moontailscommented, Dec 11, 2017

How can one loop over the entities and update them ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is useState not triggering re-render? - Stack Overflow
You're calling setNumbers and passing it the array it already has. You've changed one of its values but it's still the same array,...
Read more >
Template - Home Assistant
This feature is a great way to create entities based on webhook data (example), or update entities based on a schedule. Whenever the...
Read more >
Changelog | Entities Graphics | 1.0.0-pre.15 - Unity - Manual
AddComponent APIs to efficiently create Hybrid Rendered entities. Changed. Log warning instead of error message when shader on SMR does not ...
Read more >
How and when to force a React component to re-render
Why aren't React components re-rendering? ... Generally, forcing a React component re-render isn't best practice, even when React fails to update ...
Read more >
Timeline does not render and shows "Records could not be ...
Timeline in UCI does not render displaying the error "Records could not be ... Link-entities come both from out-of-the-box activities as well as...
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