tinymce / tinymce-angular

Official TinyMCE Angular Component
MIT License
330 stars 92 forks source link

Editor breaks when removed from template with animations #137

Closed Ploppy3 closed 2 months ago

Ploppy3 commented 4 years ago

What is the current behavior? Editor breaks when removed from template with animations. It turns into a textarea during the animation. I've tested several of my animations and all break the editor.

gif

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

https://codesandbox.io/s/tinymceangular-6kzby

<div *ngIf="editorVisible" @fadeInOut>
  <editor required></editor>
</div>
export const fadeInOut = trigger('fadeInOut', [
  state('void', style({
    opacity: 0
  })),
  state('hidden', style({
    opacity: 0
  })),
  state('visible', style({
    opacity: 1
  })),
  transition(':enter, hidden => visible', [
    animate('.5s ease', style({
      opacity: 1,
    })),
  ]),
  transition(':leave, visible => hidden', [
    animate('.5s ease', style({
      opacity: 0,
    })),
  ]),
]);

What is the expected behavior? Editor should not break when animated

Which versions of TinyMCE/TinyMCE-Angular, and which browser / OS are affected by this issue? Did this work in previous versions of TinyMCE or TinyMCE-Angular? Angular 9 with Ivy TinyMCE-Angular: 3.4.0

Ploppy3 commented 4 years ago

Since it seems to be an angular limitation, one way to partially solve this would be to give an optional @Input parameter to delay the destruction of the TinyMce editor in the ngOnDestroy call.

Ploppy3 commented 4 years ago

For reference, here is how a similar issue was fixed by another dev. https://github.com/telerik/kendo-angular/issues/1018#issuecomment-589167663

SimonFc commented 4 years ago

Might be something that tinymce-angular can handle but I do wonder how. I think we want to avoid delaying the removal of TinyMCE through other means than life cycle hooks (and similar) as I imagine that it easily could lead to bugs. Perhaps this doesn't work for your use case but as a workaround you could take care of conditionally removing tinymce-angular via an animation callback. https://codesandbox.io/s/tinymceangular-lg26p?fontsize=14&hidenavigation=1&theme=dark

To be investigated

Ploppy3 commented 4 years ago

@SimonFc even though what you propose works, I don't think it is applicable to router animations.

Edit: as explained in the link above, Angular takes care of clearing the dom, only the javascript object has to be cleared from memory in the onDestroy life cycle hook. I don't know how TinyMCE was implemented so I'm not sure if it is possible.

Ploppy3 commented 4 years ago

I implemented your solution and it indeed does not work for router animations.

tiny-stale-bot commented 3 months ago

This issue is stale because it has been open 30 days with no activity. Please comment if you wish to keep this issue open or it will be closed in 7 days.

tiny-stale-bot commented 2 months ago

This issue is stale because it has been open 30 days with no activity. Please comment if you wish to keep this issue open or it will be closed in 7 days.

tiny-stale-bot commented 2 months ago

This issue was closed because it has been stalled for 7 days with no activity.