You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bugY.XmlText.format can strip attributes outside the range provided to the function. This behavior seems to happen specifically when the YDoc is initialized via applyUpdate from an encoded update.
To Reproduce This jest test reproduces the issue.
import*asYfrom"yjs";describe("inconsistentFormatBug",()=>{it("1. Passes on fresh YDoc",()=>{constyDoc=initializeYDoc();testYjsMerge(yDoc);});it("2. Fails on YDoc initialized via an encoded update",()=>{constinitialYDoc=initializeYDoc();constyDoc=newY.Doc({gc: false});Y.applyUpdate(yDoc,Y.encodeStateAsUpdate(initialYDoc));testYjsMerge(yDoc);});});functiontestYjsMerge(yDoc: Y.Doc){constcontent=yDoc.get("text",Y.XmlText)asY.XmlText;content.format(0,6,{bold: null});content.format(6,4,{type: "text"});expect(content.toDelta()).toEqual([{attributes: {type: "text"},insert: "Merge Test",},{attributes: {type: "text",italic: true},insert: " After",},]);}functioninitializeYDoc(): Y.Doc{constyDoc=newY.Doc({gc: false});constcontent=yDoc.get("text",Y.XmlText)asY.XmlText;content.insert(0," After",{type: "text",italic: true});content.insert(0,"Test",{type: "text"});content.insert(0,"Merge ",{type: "text",bold: true});returnyDoc;}
The only difference between the setup for cases (1) and (2) is how the document is initialized, but they produce different results. In case (1), the format call is applied correctly. In case (2), it strips type attribute from the " After" text, even though it is outside of the provided range.
Describe the bug
Y.XmlText.format
can strip attributes outside the range provided to the function. This behavior seems to happen specifically when the YDoc is initialized viaapplyUpdate
from an encoded update.To Reproduce This jest test reproduces the issue.
The only difference between the setup for cases (1) and (2) is how the document is initialized, but they produce different results. In case (1), the
format
call is applied correctly. In case (2), it stripstype
attribute from the " After" text, even though it is outside of the provided range.Expected behavior I would expect case (2) to behave like case (1) and not strip out the "type" attribute.
Environment Information
Additional context We are using
yjs
withslate-yjs
and found this behavior was triggered by Slatemerge_node
operations on a newly loaded editor.We found the issue in yjs v13.5.45 but have been able to repro it in v13.6.10 as well.
Huly®: YJS-408
The text was updated successfully, but these errors were encountered: