File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -1131,7 +1131,9 @@ impl Handler {
11311131 // In this method we will not clone the values of the containers if
11321132 // they are remapped. It's the caller's duty to do so
11331133 let on_container_remap = & mut |old_id, new_id| {
1134- container_remap. insert ( old_id, new_id) ;
1134+ if old_id != new_id {
1135+ container_remap. insert ( old_id, new_id) ;
1136+ }
11351137 } ;
11361138 match self {
11371139 Self :: Map ( x) => {
Original file line number Diff line number Diff line change @@ -1513,3 +1513,31 @@ fn test_origin() {
15131513 . unwrap ( ) ;
15141514 sub. unsubscribe ( ) ;
15151515}
1516+
1517+ #[ test]
1518+ fn apply_diff_with_same_peer_id_should_not_hang ( ) {
1519+ let doc1 = LoroDoc :: new_auto_commit ( ) ;
1520+ doc1. set_peer_id ( 1 ) . unwrap ( ) ;
1521+
1522+ let doc2 = doc1. fork ( ) ;
1523+ doc2. set_peer_id ( 1 ) . unwrap ( ) ; // Same peer ID
1524+
1525+ // The key issue: setContainer creates a nested container
1526+ let map = doc2. get_map ( "root" ) ;
1527+ let nested = map
1528+ . insert_container ( "nested" , MapHandler :: new_detached ( ) )
1529+ . unwrap ( ) ; // This is what triggers the hang
1530+ nested. insert ( "key" , "value" ) . unwrap ( ) ;
1531+ doc2. commit_then_renew ( ) ;
1532+
1533+ let frontiers_before = doc1. oplog_frontiers ( ) ;
1534+ let frontiers_after = doc2. oplog_frontiers ( ) ;
1535+ let diff = doc2. diff ( & frontiers_before, & frontiers_after) . unwrap ( ) ;
1536+
1537+ // This should NOT hang
1538+ doc1. apply_diff ( diff) . unwrap ( ) ;
1539+ assert_eq ! (
1540+ doc1. get_deep_value( ) . to_json_value( ) ,
1541+ doc2. get_deep_value( ) . to_json_value( )
1542+ ) ;
1543+ }
You can’t perform that action at this time.
0 commit comments