diff --git a/.changeset/chatty-experts-clean.md b/.changeset/chatty-experts-clean.md new file mode 100644 index 00000000..94ad1e6b --- /dev/null +++ b/.changeset/chatty-experts-clean.md @@ -0,0 +1,5 @@ +--- +"loro-crdt": patch +--- + +fix: should commit before travel_change_ancestors #599 diff --git a/crates/loro-internal/src/loro.rs b/crates/loro-internal/src/loro.rs index 147ab9d6..459c5377 100644 --- a/crates/loro-internal/src/loro.rs +++ b/crates/loro-internal/src/loro.rs @@ -1635,6 +1635,7 @@ impl LoroDoc { ids: &[ID], f: &mut dyn FnMut(ChangeMeta) -> ControlFlow<()>, ) -> Result<(), ChangeTravelError> { + self.commit_then_renew(); struct PendingNode(ChangeMeta); impl PartialEq for PendingNode { fn eq(&self, other: &Self) -> bool { diff --git a/crates/loro/tests/loro_rust_test.rs b/crates/loro/tests/loro_rust_test.rs index ebbd33d2..83dfe290 100644 --- a/crates/loro/tests/loro_rust_test.rs +++ b/crates/loro/tests/loro_rust_test.rs @@ -2467,3 +2467,15 @@ fn test_rust_get_value_by_path() { assert!(doc.get_by_str_path("tree/0/2").is_none()); // Invalid child index assert!(doc.get_by_str_path("tree/0/0/1").is_none()); // Invalid grandchild index } + +#[test] +fn travel_before_commit() -> Result<(), Box> { + let doc = LoroDoc::new(); + let map = doc.get_map("metadata"); + map.insert("key", "value")?; + let last_frontiers = doc.state_frontiers(); + doc.travel_change_ancestors(&last_frontiers.to_vec(), &mut |_meta| { + std::ops::ControlFlow::Continue(()) + })?; + Ok(()) +}