In my web app, when I create a new task session on it, it will create a new prosemirror editor,and this editor will create a new empty yDoc and a new websocketProvider.
When my server detects that a new task has been created, it will push a piece of PM JSON over the server’s WebSocket based on the template of the current task.
{
"doc": {
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "file",
"attrs": {
"fileId": "Zr8SjMyrgaPurgL7Z64TGOawQwcLXpVIRDZ2tKM_5xM=",
"title": "image.jpg",
"file": '{"id":"Zr8SjMyrgaPurgL7Z64TGOawQwcLXpVIRDZ2tKM_5xM=","name":"image.jpg","size":35841,"sign":"booking.dL8dgpPtj6DvrgX5Ro0VHuC2RQENWJNOQjBwsqU54RU=:daUbm8ysr4vEhCnXaaAdFui-TQkFUJtGSjh4uq0x6R0=.B4Yrsqbl7AajF71hD63bIyP4MujfvShH85HUg6LIcQx","hasCDN":true,"type":null,"width":445,"height":412}',
"sign": "xxxx",
"imFileId": "xxx",
"extra": {},
"fromTicketId": "dL8dgpPtj6DvrgX5Ro0VHuC2RQENWJNOQjBwsqU54RU=",
},
"content": [
{"type": "text", "text": "图片.jpg"}
],
}
],
}
],
},
"selection": {"type": "text", "anchor": 223, "head": 223},
}
const pmNode = PmNode.fromJSON(_PM_SCHEMA, pmJson)
const yDoc = y_prosemirror.prosemirrorToYDoc(pmNode)
// --------------------------------------------------
const encoder = encoding.createEncoder();
const decoder = decoding.createDecoder(message);
encoding.writeVarUint(encoder, messageSync);
syncProtocol.readSyncMessage(decoder, encoder, this.yDoc, conn);
if (encoding.length(encoder) > 1) {
this.send(conn, encoding.toUint8Array(encoder));
}
However, when the frontend receives this update and applies it to the yDoc on the web page, the “file” node is in a deleted state. That means after processing the code Y.applyUpdate(doc, decoding.readVarUint8Array(decoder), transactionOrigin)
, the “file” node in the doc
is marked as deleted, and the output YXmlFragment
does not include the “file” node.