fix: should commit before travel_change_ancestors (#599)

* fix: should commit before travel_change_ancestors

* chore: changeest
This commit is contained in:
Zixuan Chen 2025-01-04 02:08:05 +08:00 committed by GitHub
parent df621a370c
commit da249109bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
"loro-crdt": patch
---
fix: should commit before travel_change_ancestors #599

View file

@ -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 {

View file

@ -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<dyn std::error::Error>> {
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(())
}