A doc JSON string has been persistenced in my backend database, but I found it difficult to load up in my frontend editor view, I used the utility function prosemirrorToYDoc, and I can see the doc rendered, but only one second…
It seems that a new state has been applied and I found meta $y_sync in console…
when I do have a options.initContent (that’s a string)
if (!options.readonly) { // if my prosemirror is readonly mode, I would not turn on anything of Y.js ...
// Y.js 协同配置:
ydoc = options.initContent
? prosemirrorToYDoc(createInitDoc(EditorSchema, options.initContent))
: new Y.Doc();
const provider = new WebsocketProvider(
'ws://localhost:2048',
options.docName,
ydoc
);
// ...
}
when StateA was just rendered but plugins not started --> sync-plugin created a tr which replaced my initial content to an empty paragraph… after applying this tr there is a new state: StateB
render view of StateB, and I just saw a flash between A and B…
I’m sorry, but this is quite a lot for me to go through. It would take a while for me to tell you exactly what is going wrong.
A few recommendations though:
Do not set the ProseMirror state AND the initial Yjs state. Ideally, just remove this line:
doc: pmNodeFromJSONString(options.initContent),
When you have the EditorView that is made collaborative using the ySyncPlugin, then there is no need to use prosemirrorToYDoc. Simply create an editor view with the Yjs document that is connected to the server using y-websocket. Then you can replace the whole editor state with a new editor state (using the ProseMirror API).
Note, however, that I discouraged “initializing” on the client-side in several threads on this forum. I’m not sure how one would prevent the case that two clients “initialize” at the same time. Yjs guarantees that all peers will always end up with the same state. But it really only can do that. Ideally, you initialize the content on the server, if you have to.
Now I found that I just need to maintain a yjs service separately with nodejs,
So I turn to integrate y-websocket and y-leveldb together,
but what should I do for readonly situation?
For example, user just get into the document view page, not editing page…
I don’t want the view page be synchronized … just a frozen one (latest to when getting into that page) is fine…
Do I need to read the persistence data ?? desperately seeking your help for my university graduation project, Thanks a lot !!!
If I do permit the readonly view page to show updates in real-time, I tried to add ySyncPlugin for non-editable ProseMirror …
Theoretically, as I provide the same docName to ydoc.getXmlFragment for both editable and read-only ProseMirror, it would all sync from the same persistence data… I don’t know why it didn’t show anything when I already have something in leveldb…
I made a quick prototype server extending y-websocket-server …
I provide a route for frontend app to fetch document from persistence, but while debugging, I found that there is actually some structure stored inside sharing ydoc, but the method yDocToProsemirrorJSON output an empty structure… How does that happen?? is that an issue ??