froala / wysiwyg-editor

The next generation Javascript WYSIWYG HTML Editor.
https://www.froala.com/wysiwyg-editor
Other
5.27k stars 673 forks source link

Froala 4.2.1: `html.get()` returns an unexpected wrapper div #4794

Open dcsaszar opened 3 months ago

dcsaszar commented 3 months ago

Update: after reporting #4795 I realized the workaround is the same, so these two issues probably have the same underlying bug:

As a workaround, these options can be set:

{
  fontFamilyDefaultSelection: "Font Family",
  fontSizeDefaultSelection: "Font Size",
}
Expected behavior.
editor.html.set("<p>Foo</p>")
editor.html.get() === "<p>Foo</p>"
Actual behavior.
editor.html.set("<p>Foo</p>")
editor.html.get() === "<div><p>Foo</p></div>"
Steps to reproduce the problem.

https://codepen.io/dcsaszar/pen/vYwpNJm

<div id="froala"></div>
import * as FroalaEditor from "froala-editor";

const element = document.getElementById("froala");
const editor = new FroalaEditor(element, {}, () => {
  editor.html.set("<p>Foo</p>")
  editor.html.get()
});
Editor version.

4.2.1

(it works as expected up to 4.2.0)

OS.

macOS 14.5 (23F79)

Browser.

Chrome 125.0.6422.142

Recording.
image
AkshayAccolite commented 2 months ago

@harasunu-narayan @dcsaszar I have found out the root cause of both the tickets this one and 4795.

The reason being that the font-size plugin and font-family plugin are not loaded with the link "https://cdn.skypack.dev/froala-editor@4.2.1" to download the editor resource. Therefore the default value for the Froala options fontSizeDefaultSelection and fontFamilyDefaultSelection remain undefined whose value are initially defined in the respective plugins, same as the values in workaround and these undefined values bypass the default value checks for default value of font-size and font-family set in the plugins. And that is the reason, the workaround works as well.

The proposed solution would be to add check for undefined for fontSizeDefaultSelection and fontFamilyDefaultSelection in the source code, with the currents checks for initial(default) values set in the respective plugins.