tinymce / tinymce-svelte

Svelte wrapper
MIT License
23 stars 6 forks source link

Editor content not updating if value changes to empty without editor interaction #22

Closed jscasca closed 1 year ago

jscasca commented 1 year ago
    @jscasca thank you for pointing it out, I may miss something but I mean the case when `value` as exported property is changed regardless of interraction with editor so the line 106 is not even executed.

The first time Svelet editor compoment instance receives 'some value' as value , it goes to editorRef.setContent(value) and it is displayed on UI becasue lastVal is empty and not equal to 'some value'. Don't touch editor directly, the lastVal is still '' but assume smth happend and value prop of Svelet editor compoment recived '', the value changed from 'some value' to '' but it is still 'some value' in editor on UI because editorRef.setContent(value) was not execute (lastVal === value === ''), basicaly mismatch between UI and state of Svelte Editor component.

I apologize but don't see this is solved by the line 106 or by other lines, as workaround I align the mismatch by using

  let mce;
  $: if (mce && value !== mce.getContent()) {
    mce.setContent(value);
  }
  const onInit = e => mce = e.detail.editor;

I hope this workaround works without unexpected side effects.

Originally posted by @EugeneGoroschenyaExt in https://github.com/tinymce/tinymce-svelte/issues/5#issuecomment-1284860642

jscasca commented 1 year ago

@EugeneGoroschenyaExt moved here for tracking purposes. This should be addressed by #23

jscasca commented 1 year ago

Fix was released for v1.0.1