ARTICLE AD BOX
The application I am working on is basically a collaborative editor, where the react clients (Slate+Yjs) will be connect to the backend sever dotnet web api using signalR, The thing is I need to maintain the current state of the YJS Document in the server as well, Since Ycs is outdated, the equivalent package is YDotNet.
I am using the following code to set the byte[] changes from the clients - Ydoc is one of the prop
public void ApplyUpdate(byte[] clientUpdate) { if (clientUpdate == null || clientUpdate.Length == 0) return; lock (_stateLock) { using (var transaction = YDoc.WriteTransaction()) { transaction.ApplyV1(clientUpdate); transaction.Commit(); } LastActivity = DateTime.UtcNow; } }And I am trying to get the full state by the below cod, here stateVector have some byte data hence it is going to var state = transaction.StateDiffV1(Array.Empty<byte>());, results in error
public byte[] GetFullState() { lock (_stateLock) { using (var transaction = YDoc.ReadTransaction()) { var stateVector = transaction.StateVectorV1(); if (stateVector == null || stateVector.Length == 0) { // Document is empty, return empty array return Array.Empty<byte>(); } // Get the entire document state var state = transaction.StateDiffV1(Array.Empty<byte>()); return state ?? Array.Empty<byte>(); } } }But it is actually throwing the following error, Even I tried initialize the doc when the obj created,
Value cannot be null. (Parameter 'source')And for reference this is my setup in react
const ydocA = useMemo(() => new Y.Doc(), []) const sharedTypeA = useMemo( () => ydocA.get('slate', Y.XmlText), [ydocA] ) const editorA = useMemo(() => { const e = withReact(createEditor()) const yEditor = withYjs(e, sharedTypeA) return withYHistory(yEditor) }, [sharedTypeA]) useEffect(() => { YjsEditor.connect(editorA) return () => { YjsEditor.disconnect(editorA) } }, [editorA])My requirements here is simple, Clients will send the data to my server, I just need to maintain the copy of it, hence I can send this to a newly joined client
