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 bug
If you set an attribute on an XmlText and delete the node in the same transaction, then undo the change, the resulting update does not restore the original attribute.
To Reproduce
Steps to reproduce the behavior:
Create an XmlText with an attribute
Set the attribute to a new value, then delete the XmlText
Create a second, remote document with the same state as the first
Undo the change in the local document
Apply the undo update to the remote document
The two docs are no longer equal
In code:
// 1. Set up a document containing an XmlText with a single attributeconstlocalYDoc=newY.Doc();constlocalSharedRoot=localYDoc.get("text",Y.XmlText);constundoManager=newY.UndoManager(localSharedRoot,{trackedOrigins: newSet([localOrigin])});consttestEmbed=newY.XmlText();testEmbed.setAttribute("type","paragraph");localSharedRoot.insertEmbed(0,testEmbed);// 2. Set the embed attribute, then delete the embedlocalYDoc.transact(()=>{testEmbed.setAttribute("type","list-item");localSharedRoot.delete(0,1);},localOrigin);// 3. Set up a second yDoc to match the state of the firstconstremoteYDoc=newY.Doc();Y.applyUpdate(remoteYDoc,Y.encodeStateAsUpdate(localYDoc));// 4. Undo the change, tracking the updateconstlocalUpdates: Uint8Array[]=[];localYDoc.on("update",(update: Uint8Array)=>{localUpdates.push(update);});undoManager.undo();// 5. Apply the update to the second yDocexpect(localUpdates).toHaveLength(1);const[undoUpdate]=localUpdates;Y.applyUpdate(remoteYDoc,undoUpdate);// 6. The two yDocs are not equal. The delete sets are different.
Expected behavior
Expect the two docs to remain equal after applying the undo update to both of them.
Screenshots
The documents diverge, as can be seen by comparing their snapshots. (received is the remote doc, expected is the local,)
Environment Information
Yjs version = 13.5.45
Additional context
Ran into the problem while using Slate Yjs and attempting to undo a list creation. Creating the list would change the type of the target element, then move it into a wrapper node, which resulted in remove and insert operations using the element. As a workaround, we've updated our list creation logic to avoid this particular order of operations.
The text was updated successfully, but these errors were encountered:
constY=require('yjs');constlocalOrigin='localOrigin';// 1. Set up a document containing an XmlText with a single attributeconstlocalYDoc=newY.Doc();constlocalSharedRoot=localYDoc.get("text",Y.XmlText);constundoManager=newY.UndoManager(localSharedRoot,{trackedOrigins: newSet([localOrigin])});consttestEmbed=newY.XmlElement();testEmbed.setAttribute("type","paragraph");localSharedRoot.insertEmbed(0,testEmbed);// 2. Set the embed attribute, then delete the embedlocalYDoc.transact(()=>{testEmbed.setAttribute("type","list-item");// localSharedRoot.delete(0, 1);},localOrigin);// 3. Set up a second yDoc to match the state of the firstconstremoteYDoc=newY.Doc();remoteYDoc.get("text",Y.XmlText);Y.applyUpdate(remoteYDoc,Y.encodeStateAsUpdate(localYDoc));// 4. Apply the update to the second yDoclocalYDoc.on("update",(update)=>{Y.applyUpdate(remoteYDoc,update);});console.log('--- before undo ---',{localYDoc: localYDoc.toJSON(),remoteYDoc: remoteYDoc.toJSON()});// 5. Undo the change, tracking the updateundoManager.undo();// 6. The two yDocs are not equal. The delete sets are different.console.log('--- after undo ---',{localYDoc: localYDoc.toJSON(),remoteYDoc: remoteYDoc.toJSON()});
Describe the bug
If you set an attribute on an XmlText and delete the node in the same transaction, then undo the change, the resulting update does not restore the original attribute.
To Reproduce
Steps to reproduce the behavior:
In code:
Expected behavior
Expect the two docs to remain equal after applying the undo update to both of them.
Screenshots
The documents diverge, as can be seen by comparing their snapshots. (
received
is the remote doc,expected
is the local,)Environment Information
Additional context
Ran into the problem while using Slate Yjs and attempting to undo a list creation. Creating the list would change the type of the target element, then move it into a wrapper node, which resulted in remove and insert operations using the element. As a workaround, we've updated our list creation logic to avoid this particular order of operations.
The text was updated successfully, but these errors were encountered: