fix: should not reset the state when calling checkout to latest (#265)

This commit is contained in:
Zixuan Chen 2024-02-10 22:19:52 +08:00 committed by GitHub
parent 3a4ed97e0b
commit 9c25e6d273
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View file

@ -260,6 +260,8 @@ impl LoroDoc {
immediate_renew: bool,
) {
if !self.auto_commit.load(Acquire) {
// if not auto_commit, nothing should happen
// because the global txn is not used
return;
}
@ -660,6 +662,11 @@ impl LoroDoc {
}
pub fn checkout_to_latest(&self) {
if !self.is_detached() {
self.commit_then_renew();
return;
}
debug_log::debug_log!("Attached {}", self.peer_id());
let f = self.oplog_frontiers();
self.checkout(&f).unwrap();

View file

@ -8,6 +8,18 @@ use loro_internal::{
};
use serde_json::json;
#[test]
fn issue_502() -> LoroResult<()> {
let doc = LoroDoc::new_auto_commit();
doc.get_map("map").insert("stringA", "Original data")?;
doc.commit_then_renew();
doc.get_map("map").insert("stringA", "Updated data")?;
doc.attach();
doc.get_map("map").insert("stringB", "Something else")?;
doc.commit_then_renew();
Ok(())
}
#[test]
fn issue_225() -> LoroResult<()> {
let doc = LoroDoc::new_auto_commit();