The document becomes blank when the DB is under high load and communication fails during connection

I am implementing collaborative text editor with lexical.
Recently, the database became overloaded and unresponsive and faced cases where data could not be read on connection.
Once the YDoc failed to read the data, document started returning blank data thereafter.
A hypothesis for the cause could be that an update was sent to the DB side that deleted all data when it became blank.
Is such a case conceivable?
Also, is there any error handling that the client side should take when the DB becomes unresponsive?
I use y-mongodb-adapter and y-websocket in serverless environment.

Yjs never deletes data automatically. This is always a user action.

From experience I still see a lot of users initializing content on the client-side (although I always advise against it…).

If you initialize content on the client-side, it might happen that you initialize data again, because you couldn’t get data from the server.

However, initializing data twice will lead to a loss of content because one version will overwrite the other with possibly empty content…

Thank you for replying.
I will improve overwrite!

I found that part of the update was corrupted, and this was the cause of the file corruption.

			ydoc.transact(() => {
				for (let i = 0; i < updates.length; i++) {
					Y.applyUpdate(ydoc, updates[i]);
				}
			});

If I ignore the broken update, the docs can read.

			ydoc.transact(() => {
				for (let i = 0; i < updates.length; i++) {
					try {
						Y.applyUpdate(ydoc, updates[i]);
					catch(e) {
						console.error(e)
					}
				}
			});

Is it ok to ignore updates that cause error?

The error during applyUpdate is below.

Error during saving transaction TypeError: readAnyLookupTable[(127 - readUint8(...))] is not a function
    at readAny (file:///var/task/index.mjs:930608:72)
    at UpdateDecoderV1.readAny (file:///var/task/index.mjs:931525:12)
    at Array.readContentAny (file:///var/task/index.mjs:936671:22)
    at readItemContent (file:///var/task/index.mjs:937279:67)
    at readClientsStructRefs (file:///var/task/index.mjs:932011:13)
    at file:///var/task/index.mjs:932147:15
    at transact (file:///var/task/index.mjs:932655:14)
    at readUpdateV2 (file:///var/task/index.mjs:932142:104)
    at applyUpdateV2 (file:///var/task/index.mjs:932193:3)
    at applyUpdate (file:///var/task/index.mjs:932195:56)

Maybe this wasn’t a valid update in the first place?

Yjs is quite thoroughly tested. So I’m interested why the error occurs, and how this update was generated. Maybe it’s not even a Yjs update?