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.

Uncaught Error: Unknown DraftEntity key.

See original GitHub issue

Hello, I have an app with several instances of draft-js where the following code works, except for one where I get the

Uncaught Error: Unknown DraftEntity key..

I have:

const entityKey = Entity.create('separator', 'IMMUTABLE', {});
    this.props.setEditorState(
      AtomicBlockUtils.insertAtomicBlock(
        this.props.getEditorState(),
        entityKey,
        '-'
      )
    );

I have tried, with the same result:

const editorState = this.props.getEditorState();
    const contentState = editorState.getCurrentContent();
    const entityKey = contentState.createEntity('separator', 'IMMUTABLE', {});
    this.props.setEditorState(
      AtomicBlockUtils.insertAtomicBlock(
        this.props.getEditorState(),
        entityKey,
        '-'
      )
    );
  1. I have checked that I only have one copy of draft-js in my npm list of packages.
  2. This is completely unrelated to the use of backspaces. (Other issues with the same error talked about this)
  3. I have tried adding a whitespace ’ ’ in the key as suggested in other issues, with no luck.

I am not really sure of what does the error mean nor how to debug it so any help is greatly appreciated!

PS: Again, the code works smoothly for the other several instances of draft-js. I can’t really see any differences since I call MyEditor.jsx in the same manner.

FULL STACK TRACE

Uncaught Error: Unknown DraftEntity key. at invariant (bundle.js:10279) at Object.__get (bundle.js:68045) at ContentState.getEntity (bundle.js:67837) at bundle.js:81802 at findRangesImmutable (bundle.js:65705) at ContentBlock.findEntityRanges (bundle.js:65647) at findLinkEntities (bundle.js:81800) at bundle.js:68912 at Array.forEach (<anonymous>) at CompositeDraftDecorator.getDecorations (bundle.js:68900) invariant @ bundle.js:10279 __get @ bundle.js:68045 getEntity @ bundle.js:67837 (anonymous) @ bundle.js:81802 findRangesImmutable @ bundle.js:65705 findEntityRanges @ bundle.js:65647 findLinkEntities @ bundle.js:81800 (anonymous) @ bundle.js:68912 getDecorations @ bundle.js:68900 generate @ bundle.js:84368 (anonymous) @ bundle.js:84216 (anonymous) @ bundle.js:63441 (anonymous) @ bundle.js:63511 (anonymous) @ bundle.js:63257 (anonymous) @ bundle.js:63124 List.__iterate @ bundle.js:62631 OrderedMap.__iterate @ bundle.js:63123 ToKeyedSequence.__iterate @ bundle.js:63255 filterSequence.__iterateUncached @ bundle.js:63508 seqIterate @ bundle.js:61043 Seq.__iterate @ bundle.js:60713 mappedSequence.__iterateUncached @ bundle.js:63440 seqIterate @ bundle.js:61043 Seq.__iterate @ bundle.js:60713 forEach @ bundle.js:64811 (anonymous) @ bundle.js:62386 Map.withMutations @ bundle.js:61778 mergeIntoCollectionWith @ bundle.js:62375 mergeIntoMapWith @ bundle.js:62348 Map.merge @ bundle.js:61729 regenerateTreeForNewBlocks @ bundle.js:84213 (anonymous) @ bundle.js:83846 Map.withMutations @ bundle.js:61778 set @ bundle.js:83816 push @ bundle.js:84087 insertAtomicBlock @ bundle.js:82086 onClick @ bundle.js:91796 (anonymous) @ bundle.js:8631 ReactErrorUtils.invokeGuardedCallback @ bundle.js:15849 executeDispatch @ bundle.js:15634 executeDispatchesInOrder @ bundle.js:15657 executeDispatchesAndRelease @ bundle.js:15313 executeDispatchesAndReleaseTopLevel @ bundle.js:15324 forEachAccumulated @ bundle.js:15948 processEventQueue @ bundle.js:15524 runEventQueueInBatch @ bundle.js:15251 handleTopLevel @ bundle.js:15261 handleTopLevelImpl @ bundle.js:37111 perform @ bundle.js:18775 batchedUpdates @ bundle.js:37029 batchedUpdates @ bundle.js:18232 dispatchEvent @ bundle.js:37186

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
roundrobincommented, Mar 10, 2018

contentState.createEntity is not returning an entityKey anymore, instead it returns a contentState.

So you have to get the key via this method:

const contentStateWithEntity =  contentState.createEntity("CUSTOM_TYPE", "IMMUTABLE", {
});
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
1reaction
IzaGzcommented, Nov 1, 2017

Hello the problem still occurs on production. What is solution? anyone knows?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unknown DraftEntity key: null. · Issue #609 - GitHub
I solved this error. I do a function which one add an image into editor, it's mean I have to get the link...
Read more >
Unknown DraftEntity key when inserting media in Draftjs
I solve the problem with adding one space so I convert : editorState:AtomicBlockUtils.insertAtomicBlock( newEditorState, entityKey, '' ).
Read more >
A brand new website interface for an even better experience!
Uncaught Invariant Violation: Unknown DraftEntity key: null.
Read more >
draft.js error: Unknown DraftEntity key: null - CSDN博客
最近在用draft.js编写富文本编辑器的时候遇到一个错误提示:Unknown DraftEntity key: null ,当时是写插入图片这一项的时候出现的,一开始还以为官方 ...
Read more >
draft.js error: Unknown DraftEntity key: null - CodeAntenna
最近在用draft.js编写富文本编辑器的时候遇到一个错误提示:Unknown DraftEntity key: null ,当时是写插入图片这一项的时候出现的,一开始还以为官方出bug了,后来去 ...
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