'deserializeHTMLToDocumentFragment' changes HTML structure of div elements
Hi, first of all thanks for this repo and all the plugins, it's been really really helpful!
Issue
So about my issue: I'm currently working on using a slate rich text formatting with HTML on an element that only had text inside it before. The initial value is Deserialized paragraph here.. Now that I added usage of slate plugins (for simplification, let's say only BlockquotePlugin), I see a weird behavior where it lets me add the blockquote, but after serializing and then deserializing the slate value, the blockquote is removed after each change - this is visible in the video below or there is a reproducible test case available here.
Am I missing something during the serialization/deserialization process which would prevent this issue or is this a bug? Any help would be really appreciated. 🙏
More details from investigation
I see that when I pass the initial value, it's serialized as <div>Deserialized paragraph here.</div> (the serializer automatically wraps the initial value text with div) and when I add the blockquote, it's then serialized to this:
<div>Deserialized paragraph here.</div><blockquote>blockquote</blockquote>
This works ok and I can edit the value and add any other elements, e.g. another blockquote. But when I save this deserialized string to database and use it as initial value when opening the editor again, right when I click into the editor the value is changed to:
<div>Deserialized paragraph here.<blockquote class="slate-blockquote">Blockquote</blockquote></div>
so now the div is wrapping the whole element. And it seems this results in the issue, where if you change anything in the input, it will remove the blockquote, as seen on the video below.
https://user-images.githubusercontent.com/8395106/108879635-bf368c00-7601-11eb-8c70-70584e2275e1.mov
Any news on this, please? Maybe there's some quick workaround for this?
Thank you in advance!
There is indeed a div wrapping all the blocks, as you can see in the console of this sandbox. Can you try to reproduce in it?
Thank you for the answer, @zbeyens! 🙏 I've tried to reproduce the issue in the sandbox from your previous message (I've just removed the other initial values in that sandbox), in that one it crashed (attaching a video), here's a link to the fork.
In the sandbox mentioned in the original issue description, it doesn't crash, but still removes the blockquote.
The main issue for us here is not that it wraps the whole value thing into a div, but that it changes the actual structure, which then results in removal of blockquote.
https://user-images.githubusercontent.com/8395106/110514589-bff21680-8107-11eb-91ca-c70e7e704d4e.mov
Here is the problem: the div element is not deserialized as a paragraph but as a leaf (text), you can see that it works for p instead. The reason behind that is div is too much generic and we don't want to create a paragraph for a div that can just be a "wrapper". The workaround is to use p or div + option p.deserialize to add a custom class name to the deserializer rules.
These are the default rules for paragraph.