yjs / y-webrtc

WebRTC Connector for Yjs
MIT License
448 stars 109 forks source link

emit 'sync' #54

Closed wmertens closed 12 months ago

wmertens commented 12 months ago

Checklist

[x] Are you reporting a bug? Use github issues for bug reports and feature requests. For general questions, please use https://discuss.yjs.dev/ [x] Try to report your issue in the correct repository. Yjs consists of many modules. When in doubt, report it to https://github.com/yjs/yjs/issues/

Is your feature request related to a problem? Please describe.

When implementing a Lexical editor with the Collaborative plugin, it expects the provider to emit 'sync' so that it can initialize the state, just like y-websocket

Describe the solution you'd like

When it's clear that everything is synced, emit 'sync'

Describe alternatives you've considered

I did setTimeout(() => provider.emit('sync', [true]), 0) for now ;-)

dmonad commented 12 months ago

In y-websocket we can sync with the backend / the global source of truth. But when should we emit sync when there are only clients (or no client at all)? When are we truly synced with the global state when there is no central source of truth?

It was my intention not to emit sync because its behavior is unclear in p2p apps.

In p2p apps, it is not clear who should initialize content. You can absolutely emit sync manually. But note that if every client "initializes" content, then there is a decent chance that content will be overwritten with stale content. You might be able to find your own "coordination" approach and decide which client should initialize. But this is out of scope of y-webrtc.