@@ -405,8 +405,9 @@ mod test {
405405 use crate :: preclude:: { Collab , Doc , PermanentUserData } ;
406406 use std:: collections:: { HashMap , HashSet } ;
407407 use uuid:: Uuid ;
408+ use yrs:: types:: ToJson ;
408409 use yrs:: updates:: decoder:: Decode ;
409- use yrs:: { ReadTxn , Snapshot , StateVector , Text , Transact , Update } ;
410+ use yrs:: { ReadTxn , Snapshot , StateVector , Text , Transact , Update , any } ;
410411
411412 #[ test]
412413 fn add_or_remove_user_mappings ( ) {
@@ -550,4 +551,21 @@ mod test {
550551 uid. to_string( ) . into( )
551552 ) ;
552553 }
554+
555+ #[ test]
556+ fn collab_doesnt_fill_user_data_automatically_if_no_data_was_written ( ) {
557+ let uid = 1 ;
558+ let client_id = default_client_id ( ) ;
559+ let oid = Uuid :: new_v4 ( ) ;
560+ let origin = CollabOrigin :: Client ( CollabClient :: new ( uid, "device-1" ) ) ;
561+ let options = CollabOptions :: new ( oid, client_id) . with_remember_user ( true ) ;
562+ let mut collab = Collab :: new_with_options ( origin, options) . unwrap ( ) ;
563+
564+ // we use mutable transaction but we don't write anything
565+ let json = collab. data . to_json ( & collab. context . transact_mut ( ) ) ;
566+ assert_eq ! ( json, any!( { } ) ) ;
567+
568+ let pud = collab. user_data ( ) . unwrap ( ) ;
569+ assert ! ( pud. user_by_client_id( client_id) . is_none( ) ) ;
570+ }
553571}
0 commit comments