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.

Intermittent issues with TinyMCE React component

See original GitHub issue

What is the current behavior?

Hi, I am trying to use the tinyMCE React component inside my web app.

My web app is a listing of car engines. The user can go in and edit the description if needed using tinyMCE.

I am using a selector that targets a class name because the web app can display up to 10 possible tinyMCE instances at a time.

I’d say 50% of the time it works wonderfully, and 50% of the time something bad happens.

Here are the 50/50 odds of what could happen when loading:

  • TinyMCE editor loads properly, all the buttons and controls show up, everything is good, no issues
  • TinyMCE editor doesn’t load at all, no visible editor
  • TinyMCE editor loads, but all the button and control icons inside the editor say, “Not Found”

This is what the source looks like when TinyMCE editor doesn’t load at all:

<div class="engineDescription">
	<textarea id="tiny-react_3380820141622576500515" style="visibility: hidden;"></textarea>
</div>

Here is the source when it does load correctly or loads but all the icons say , “Not Found”

<div class="engineDescription">
	<textarea id="tiny-react_52448036051622576555748" style="display: none;" aria-hidden="true"></textarea>
	<div role="application" class="tox tox-tinymce tox-tinymce--toolbar-sticky-off" aria-disabled="false" style="visibility: hidden; height: 500px;">
	<div class="tox-editor-container"><div data-alloy-vertical-dir="toptobottom" tabindex="-1" class="tox-editor-header">
	/* etc */
</div>

I render the component like this:

this.renderComponent(tinyMCEcomponent, { engineId: this.model.id, engineDescription: this.model.attributes.engineDescription, engine: this.model.attributes }, '.engineDescription');

And here is the tinyMCE React component:

import React, { useState, useEffect } from 'react';
import { Editor } from '@tinymce/tinymce-react';

import axios from 'axios';


const App = (props) => {
    const [engineDescription, setEngineTextState] = useState(props.engineDescription || "Engine Text...");
    var rteContent = '';

    if (localStorage.getItem('engineState')) {
        rteContent = localStorage.getItem('engineState');
    } else {
        rteContent = engineDescription;
    }

    const [engineState, setEngineState] = useState(rteContent);

    useEffect(() => {
        localStorage.setItem('engineState', engineState)
    }, [engineState]);


    const updateEngineText = (content) => {
        const request = axios.put(`/api/enginerManager/123/engineDescription`, JSON.stringify(content), {
            headers: {
                'Content-Type': 'application/json'
            }
        });
        setEngineState(content);
    }
    return (
        <Editor
            initialValue={rteContent}
            init={{
                selector: ".engineDescription",
                height: 500,
                menubar: 'file edit view insert format tools table help',
                plugins: [
                    'advlist autolink lists link image charmap print preview anchor',
                    'searchreplace visualblocks code fullscreen',
                    'insertdatetime media table paste code help wordcount'
                ],

            }}
            value={engineState}
            onEditorChange={updateEngineText}
        />
    )
}

    export default App;

I’m kind of at a loss of what to do. I’ve read through numerous tutorials on the web and tried different things. I tried an editor called ckeditor that worked all the time, but I like tinyMCE so much better.

So I’m wondering, what could I be doing wrong? I’ve tried so many things and ideas that I’m just out of them. I don’t know where to turn to next.

I was hoping this site might provide some answers.

Thank you

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

@tinymce/tinymce-react": “^3.12.6”

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
tiny-jamescommented, Jun 2, 2021

I am using a selector that targets a class name because the web app can display up to 10 possible tinyMCE instances at a time.

This method does not work with the tinymce-react integration. Every place your webapp should display tinymce you need to put the <Editor/> tag. The selector setting is completely ignored by the tinymce-react integration by design.

I took your code and made a demo using multiple editors: https://codesandbox.io/s/tinymcereact-multiple-editors-z03vw

Note that the way you were setting the initial value caused an infinite loop with the event callbacks so I made it into a useState call.

0reactions
tiny-jamescommented, Jan 20, 2022

TinyMCE uses an iframe to display its content which allows separation of styling and selection.

When an iframe is removed from the DOM, even if it is added back immediately, it loses the contained state. This is what is causing your reordering operation to fail.

Currently the only workarounds are to force a re-init of tinymce (by using a different key) after the move or to use inline mode which can be moved provided you don’t clone the nodes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TinyMCE not working: possible causes and fixes
There are a couple of possible reasons of TinyMCE not working - you can fix those easily and we prepared detailed instructions for...
Read more >
React integration | Docs - TinyMCE
The Official TinyMCE React component integrates TinyMCE into React projects. This procedure creates a basic React application containing a TinyMCE editor ...
Read more >
TinyMCE React integration technical reference
Technical reference for the TinyMCE React integration. ... Using the TinyMCE React component as a uncontrolled component. Using the TinyMCE React component ......
Read more >
How to fix uncaught reference error: TinyMCE is not defined
There's an essential troubleshooting step to take to solve the problem. ... a listener to react when customers interact with an element.
Read more >
Hosting the TinyMCE package with the React framework
The Official TinyMCE React component integrates TinyMCE into React projects. This procedure creates a basic React application containing a TinyMCE editor.
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