@@ -170,6 +170,8 @@ export function useYjsCollaboration(
170170 onBootstrap ,
171171 ) ;
172172
173+ useAwareness ( binding , provider ) ;
174+
173175 return useYjsCursors ( binding , cursorsContainerRef ) ;
174176}
175177
@@ -251,7 +253,6 @@ export function useYjsCollaborationV2__EXPERIMENTAL(
251253
252254 useEffect ( ( ) => {
253255 const { root} = binding ;
254- const { awareness} = provider ;
255256
256257 if ( diffSnapshots ) {
257258 renderSnapshot__EXPERIMENTAL (
@@ -300,15 +301,9 @@ export function useYjsCollaborationV2__EXPERIMENTAL(
300301 } ,
301302 ) ;
302303
303- const onAwarenessUpdate = ( ) => {
304- syncCursorPositions ( binding , provider ) ;
305- } ;
306- awareness . on ( 'update' , onAwarenessUpdate ) ;
307-
308304 return ( ) => {
309305 root . unobserveDeep ( onYjsTreeChanges ) ;
310306 removeListener ( ) ;
311- awareness . off ( 'update' , onAwarenessUpdate ) ;
312307 } ;
313308 } , [ binding , provider , editor , diffSnapshots ] ) ;
314309
@@ -322,6 +317,8 @@ export function useYjsCollaborationV2__EXPERIMENTAL(
322317 onBootstrap ,
323318 ) ;
324319
320+ useAwareness ( binding , provider ) ;
321+
325322 return binding ;
326323}
327324
@@ -423,6 +420,20 @@ function useProvider(
423420 } , [ connect , disconnect , editor ] ) ;
424421}
425422
423+ function useAwareness ( binding : Binding | BindingV2 , provider : Provider ) {
424+ useEffect ( ( ) => {
425+ const { awareness} = provider ;
426+ const onAwarenessUpdate = ( ) => {
427+ syncCursorPositions ( binding , provider ) ;
428+ } ;
429+ awareness . on ( 'update' , onAwarenessUpdate ) ;
430+
431+ return ( ) => {
432+ awareness . off ( 'update' , onAwarenessUpdate ) ;
433+ } ;
434+ } , [ binding , provider ] ) ;
435+ }
436+
426437export function useYjsCursors (
427438 binding : BaseBinding ,
428439 cursorsContainerRef ?: CursorsContainerRef ,
0 commit comments