-
-
Notifications
You must be signed in to change notification settings - Fork 191
Closed
Labels
Description
The problem I am facing
Hocuspocus will immediately convert any Y.Doc returned by the onLoadDocument hook into an update.
This is the relevant code from hocuspocus:
await this.hooks('onLoadDocument', hookPayload, (loadedDocument: Doc | undefined) => {
// if a hook returns a Y-Doc, encode the document state as update
// and apply it to the newly created document
// Note: instanceof doesn't work, because Doc !== Doc for some reason I don't understand
if (
loadedDocument?.constructor.name === 'Document'
|| loadedDocument?.constructor.name === 'Doc'
) {
applyUpdate(document, encodeStateAsUpdate(loadedDocument))
}
})Since we load documents in the update format anyway, it's just redundant work for us to convert our updates to Y.Docs just to be able to return them from the onLoadDocument hook.
The solution I would like
Change the onLoadDocument hook to have the return type Y.Doc | { update: Uint8Array, encodingVersion: number } instead of just Y.Doc.
CC: @ViktorQvarfordt
Reactions are currently unavailable