From b94021498571cf7ac42f2896ca0abc82f15d823a Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Fri, 17 Nov 2023 23:05:20 +0800 Subject: [PATCH] fix: from snapshot should enable auto commit --- crates/loro-wasm/src/lib.rs | 3 ++- loro-js/tests/basic.test.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/loro-wasm/src/lib.rs b/crates/loro-wasm/src/lib.rs index 83c80368..d0a22c9a 100644 --- a/crates/loro-wasm/src/lib.rs +++ b/crates/loro-wasm/src/lib.rs @@ -238,7 +238,8 @@ impl Loro { /// #[wasm_bindgen(js_name = "fromSnapshot")] pub fn from_snapshot(snapshot: &[u8]) -> JsResult { - let doc = LoroDoc::from_snapshot(snapshot)?; + let mut doc = LoroDoc::from_snapshot(snapshot)?; + doc.start_auto_commit(); Ok(Loro(doc)) } diff --git a/loro-js/tests/basic.test.ts b/loro-js/tests/basic.test.ts index 8d522448..fea7e0a0 100644 --- a/loro-js/tests/basic.test.ts +++ b/loro-js/tests/basic.test.ts @@ -129,6 +129,15 @@ describe("import", () => { a.import(b.exportFrom(a.version())); expect(a.getText("text").toString()).toBe("abc"); }); + + it("from snapshot", () => { + const a = new Loro(); + a.getText("text").insert(0, "hello"); + const bytes = a.exportSnapshot(); + const b = Loro.fromSnapshot(bytes); + b.getText("text").insert(0, "123"); + expect(b.toJson()).toStrictEqual({ "text": "123hello" }) + }) }); describe("map", () => {