Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with multiple visits #292

Open
maks112v opened this issue Nov 13, 2022 · 5 comments
Open

Doesn't work with multiple visits #292

maks112v opened this issue Nov 13, 2022 · 5 comments

Comments

@maks112v
Copy link

maks112v commented Nov 13, 2022

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.

@Faq
Copy link

Faq commented Nov 14, 2022

What version of tinymce?

@itsterry
Copy link

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

@xeron
Copy link

xeron commented Jul 9, 2023

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?

@jasonfb
Copy link

jasonfb commented Oct 7, 2023

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:
tinymce-with-turbo2

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.

@jasonfb
Copy link

jasonfb commented Oct 7, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants