TinyMCE not working on page loaded by turbo

TinyMCE editor is initialized once on page load. However, if there interaction is managed by Turbo, the initialization is not executed, causing the textarea to remain as a plain textarea.

To properly use TinyMCE with turbo, the initialization code is migrated into a Stimulus controller.

import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
    connect() {
        tinymce.init({});
    }
    disconnect() {
        tinymce.remove();
    }
}

And in your view:

<div data-controller="editor">
    <!-- your Textarea -->
</div>

This ties the initiation code with the connect/disconnect event from this view.


AI Summary
gpt-4o-2024-05-13 2024-07-16 00:40:49
TinyMCE editor fails to initialize on pages loaded by Turbo, leaving textareas plain. The solution involves migrating the initialization code into a Stimulus controller, which ensures proper editor loading and removal during Turbo interactions.
Chrome On-device AI 2024-07-20 05:01:09

Share Article