ueberdosis / hocuspocus

The CRDT Yjs WebSocket backend for conflict-free real-time collaboration in your app.
https://tiptap.dev/docs/hocuspocus/introduction
MIT License
1.19k stars 115 forks source link

DirectConnection transact context not passed to document lifecycle hooks #833

Open raimohanska opened 2 months ago

raimohanska commented 2 months ago

Description

If you pass a context (or transactionOrigin) to the transact method of DirectConnection, the context is not applied to the modifications you perform within your transaction function. So if you have, for instance, onChange hooks in your server extensions, they will not see the given context.

As a workaround, one can of course do something like

directConnection.transact((document) => {
  document.transact((document) => {
    // Perform actual transaction here
  }, myContext)
}, myContext)

... but to me this seems unnecessary, as it would seem intuitive for the DirectConnection to take care of this. Maybe, on this line one could instead do

this.document.transact(transaction, transactionOrigin)

This way, I suppose, it would work as one expect. Let me know what you think.

And thanks for HocusPocus! It generally seems like a great backend for Y.js applications and has pretty good documentation.