@@ -411,8 +411,12 @@ export class YSocketIO {
411411 changed = tr . changed . size > 0
412412 } )
413413 Y . transact ( existDoc . ydoc , ( ) => {
414- for ( const msg of updates ) Y . applyUpdate ( existDoc . ydoc , msg )
414+ for ( const msg of updates ) {
415+ if ( msg . length === 0 ) continue
416+ Y . applyUpdate ( existDoc . ydoc , msg )
417+ }
415418 for ( const msg of awareness ) {
419+ if ( msg . length === 0 ) continue
416420 AwarenessProtocol . applyAwarenessUpdate ( existDoc . awareness , msg , null )
417421 }
418422 } )
@@ -429,7 +433,6 @@ export class YSocketIO {
429433 this . debouncedPersist ( namespace , doc . ydoc )
430434 this . namespaceDocMap . get ( namespace ) ?. ydoc . destroy ( )
431435 this . namespaceDocMap . set ( namespace , doc )
432- await this . client . trimRoomStream ( namespace , 'index' , nsp . sockets . size === 0 )
433436 }
434437
435438 /**
@@ -456,6 +459,7 @@ export class YSocketIO {
456459 const doc = this . debouncedPersistDocMap . get ( namespace )
457460 if ( ! doc ) return
458461 await this . client . store . persistDoc ( namespace , 'index' , doc )
462+ await this . client . trimRoomStream ( namespace , 'index' , true )
459463 this . debouncedPersistDocMap . delete ( namespace )
460464 this . debouncedPersistMap . delete ( namespace )
461465 } ,
0 commit comments