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.

Mention Plugin - Error thrown when displaying mentions in readOnly Editor

See original GitHub issue

Mentions are correctly inserted in the Editor in editing mode but do not work in readOnly mode. The thrown error: Unhandled promise rejection TypeError: mention.has is not a function(…)

Details of the error The error comes from this code if (mention.has('link')) As Entity.get(entityKey) returns an object, the code tries to use .has() on an Object so it throws an exception.

Scenario to reproduce this error:

  1. In edit mode : add some mentions
  2. Save your rawContent somewhere like in a database so you can reuse it later (My sample below)
  3. Display your content in an readOnly Editor

If you want to test it quickly, here is my rawContent:

{"entityMap": {"0": {"type": "mention", "mutability": "IMMUTABLE", "data": {"mention": {"link": "/user/17", "name": "Maxime Rota", "avatar": "http://1A922.http.par01.cdn.softlayer.net/preprod/line_operator.jpg"}}}}, "blocks": [{"key": "en8l2", "depth": 0, "inlineStyleRanges": [], "type": "unstyled", "entityRanges": [{"key": 0, "length": 11, "offset": 0}], "text": "Maxime Rota "}]}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Stanleycommented, May 3, 2016

Here is the workaround that solved this issue for me:

var fromJS = require('immutable').fromJS

_.forEach(rawContent.entityMap, function(val, key) {
  val.data.mention = fromJS(val.data.mention)
})

var contentState = Draft.convertFromRaw(rawContent)
var editorState = Draft.EditorState.createWithContent(contentState)

Hope this helps with finding more permanent solution for this bug.

0reactions
nikgrafcommented, Jun 29, 2016

This got already fixed in the latest version of the mentions plugin. It not accepts immutable data structures as well as plain JS objects: https://github.com/draft-js-plugins/draft-js-plugins/pull/326

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot edit in read-only editor VS Code - Stack Overflow
Go to File > Preference > Settings then; type: run code and scroll down until you see code-runner: Run in terminal, There will...
Read more >
Error codes - CKEditor 5 Documentation
Technically speaking, this error occurs because after adding a plugin to an existing editor build the dependencies of this plugin are being duplicated....
Read more >
Unity 2019.2.2f1 - Gradle Build Failed.
Gradle fails to build and throws the following error: CommandInvokationFailure: Gradle build failed. C:\Program Files\Unity\Hub\Editor\2020.1.
Read more >
Troubleshoot plug-ins - Power Apps - Microsoft Learn
This error simply means that the worker process running your plug-in code crashed. The reason it crashed may be your plug-in, but it...
Read more >
The option setting 'android.enableR8=false' is deprecated.
After that build has started throwing following error. ... I have tried many solutions mentioned on different forums, changed Gradle version ...
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