Open productivityindustries opened 2 years ago
Hi @productivityindustries,
This isn't a bug - it's an intentional tradeoff of the representation of the slate document inside yjs. Slate-yjs relies on slates default normalization rules to be run after applying a remote change, which will add the empty text elements back in, causing the remote and local state to match (except for formatting attributes on blank text nodes). Appling changes with mismatches in the empty text nodes won't cause issues.
While we could sync the formatting attributes of empty text nodes using yjs embeds, I intentionally decided not to support it for now, as slate treats them as disposable anyway (e.g., it will merge them, ignoring the formatting attributes). So storing any critical information on them should be avoided. Instead, you could probably add back the URL attribute using a normalization rule in your example, although it's hard to say without knowing the specifics.
Hi @productivityindustries, I have the same problem, because the empty text not sync, the doc init but link(inline element) not surround with empty text node after refresh browser. Did you solve the problem?
Hi @productivityindustries, I have the same problem, because the empty text not sync, the doc init but link(inline element) not surround with empty text node after refresh browser. Did you solve the problem?
Hi @productivityindustries @BitPhinix,
Call Editor.normalize(editor, {force: true})
when first applyRemoteEvents
can solve this problem, but I don't know if there other problems
Hi, I wrote a simple unit test to validate the conversion from Slate nodes to Yjs shared objects and reverse and, to my surprise, it fails.
Test output:
I took as an example a document created in our webapp with an inline image (Slate automatically surrounds inline elements with empty texts) with an hyperlink attached (an empty text with attributes is perfectly valid in Slate). Digging into the code, I realized the issue root cause is in the Yjs business logic skipping any insertion of empty strings. This misalignment breaks synchronization between clients, and also the storing of document data on the server side. The bridge between Slate and Yjs should be able to fully reconstruct the original node structure, as far as it complies with the Slate model.