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.

"editor.selection is null" thrown when removing and re-adding editor

See original GitHub issue

What is the current behavior?

I have two themes in my app: dark & light, and also I have a page in my app that has TinyMCE editor in it and a page that don’t. For the theme switching to work, I had to keep the value of editor in one state, and on theme change, I had to remove the editor from the page, and re-add it later with a little delay. It was the only way that theme switching would work.

Now this theme switching mechanism (removing and re-adding later) caused a problem. whenever I load editor, navigate to another page, and come back later, an error: editor.selection is null is thrown. Or whenever I toggle theme twice, the same error is thrown. Note that this error is thrown only when I switch pages fast, Or I toggle theme fast

Please provide the steps to reproduce and if possible a minimal demo of the problem via codesandbox.io or similar.

https://codesandbox.io/s/dreamy-napier-24xg8?file=/src/App.js

Try moving between Path1 and Path2 fast, or try clicking on Toggle Theme button fast

What is the expected behavior?

Nothing to be thrown and editor being remounted safely

Which versions of TinyMCE, and which browser / OS are affected by this issue? Did this work in previous versions of TinyMCE or tinymce-react?

Firefox 83 TinyMCE-dev: {"releaseDate": "2020-11-25"} @tinymce/@tinymce-react: 3.8.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
tiny-jamescommented, Dec 14, 2020

Jira ref: INT-2282

2reactions
tiny-jamescommented, Dec 11, 2020

It seems like the editor is getting destroyed after it has started loading stylesheets but before they load. When the stylesheets load they trigger the next step in the editor loading process however the editor has already been destroyed and references to the selection have been cleared.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'addEventListener' of null - Stack Overflow
I think the easiest approach would be to just check that el is not null before adding an event listener: var el =...
Read more >
7561 (IE 'editor.getSelection()' is null or not an object) - CKEditor
According to the documentation, and my observations, editor.getSelection() can return null. This statement should be wrapped in a conditional block to avoid ...
Read more >
Transaction - ProseMirror Reference manual
When it has a selection property, that should be a valid selection in the given document, ... Removes the editor from the DOM...
Read more >
sed, a stream editor - GNU.org
They perform two sed operations: deleting any lines matching the regular expression /^foo/ , and replacing all occurrences of the string ' hello...
Read more >
Changelog | Package Manager UI website
Fix UV editor throwing null if shader has no _MainTex uniform. ... Fix bug when "Meshes are Assets" is enabled where deleting a...
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