y-durableobjects icon indicating copy to clipboard operation
y-durableobjects copied to clipboard

Subdoc Support

Open zhanghaocong opened this issue 8 months ago • 2 comments

Hi naporin0624,

Any plans to support subdocuments? If so, could you outline a potential implementation approach? I’d be happy to assist in development.

zhanghaocong avatar Apr 27 '25 09:04 zhanghaocong

^^^

flbn avatar Aug 12 '25 14:08 flbn

Subdoc synchronization should work by creating a WebSocketProvider instance for each subdoc.guid. Since DurableObjects make it easy to scale websocket servers by ID, I think you can handle subdoc connections the same way as doc connections. (ref: https://docs.yjs.dev/api/subdocuments)

doc.on('subdocs', ({ loaded }) => {
  loaded.forEach(subdoc => {
    new WebrtcProvider(subdoc.guid, subdoc)
  })
})
doc.getSubdocs() // Get the Set<Y.Doc> of all subdocuments

If this works well, I'd be happy if you could create a PR to add it as an example.

If the increase in websocket connections per subdoc is a concern, the approach discussed here might be useful: https://discuss.yjs.dev/t/multiple-room-sync-subdocument/403/3

naporin0624 avatar Aug 13 '25 07:08 naporin0624