Doesn't work with multiple visits
maks112v opened this issue · 5 comments
On Rails 7 using turbo tinymce doesn't load after a route is visited more than one time in a single user session. It renders a large text area instead of tinymce
For anyone looking my current solution was to add data: { turbo: 'false' }
to all links going to screen containing tinymce.
What version of tinymce?
There's a nice write-up here of how to avoid having to add data: { turbo: false }
here:
https://dev.to/djchadderton/making-tinymce-work-with-rails-turbolinks-and-stimulus-2ooa
...but I couldn't get it to work 100% of the time
Just noticed the same issue while trying to integrate tinymce into avo admin panel which uses Turbo. Is it possible to fix on the gem side?
I have this problem. The issue is that the variable tinymce
doesn't survive between the turbo reloads
if I initialize tiny inside or outside of the turbo:load listener I get the same effect, first interaction only works, subsequent interactions do not work:
my code is as follows:
<script>
TinyMCERails.configuration.default = {
selector: "textarea.tinymce",
cache_suffix: "?v=6.7.0",
menubar: "insert view format table tools",
toolbar: ["bold italic | link | undo redo | forecolor backcolor | bullist numlist outdent indent | table | uploadimage | code"],
plugins: "table,fullscreen,image,code,searchreplace,wordcount,visualblocks,visualchars,link,charmap,directionality,nonbreaking,media,advlist,autolink,lists",
images_upload_url: "/uploader/image"
};
document.addEventListener('turbo:load', function() {
console.log("connecting tiny... the tinymce object is", tinymce)
TinyMCERails.initialize('default', {
selector: 'textarea.tinymce',
convert_urls: true,
uploadimage: true
});
});
document.addEventListener('turbo:submit-end', function() {
tinymce.remove(); // Remove existing TinyMCE instances
tinymce.init({
selector: 'textarea.tinymce',
// Other TinyMCE configuration options
});
});
</script>
I also tried with this listener on the turbo load but it's the same effect
tinymce.init({
selector: 'textarea.tinymce', // Add the appropriate selector for your textareas
// Other TinyMCE configuration options
});
I think the problem comes from the tinymce
variable not surviving between turbo interactions.
opened new issue #308
I have a fix over there.
after examining more closely, I can see that much of the TinyMCE Javascript code is written for Turbolinks, not Turbo. I'd recommend that this gem stay as-is and a new gem be built to replace it for Turbo, which can then address all of these turbo issues more holistically.