Skip to content

Commit b940214

Browse files
committed
fix: from snapshot should enable auto commit
1 parent 089d05e commit b940214

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

crates/loro-wasm/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ impl Loro {
238238
///
239239
#[wasm_bindgen(js_name = "fromSnapshot")]
240240
pub fn from_snapshot(snapshot: &[u8]) -> JsResult<Loro> {
241-
let doc = LoroDoc::from_snapshot(snapshot)?;
241+
let mut doc = LoroDoc::from_snapshot(snapshot)?;
242+
doc.start_auto_commit();
242243
Ok(Loro(doc))
243244
}
244245

loro-js/tests/basic.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ describe("import", () => {
129129
a.import(b.exportFrom(a.version()));
130130
expect(a.getText("text").toString()).toBe("abc");
131131
});
132+
133+
it("from snapshot", () => {
134+
const a = new Loro();
135+
a.getText("text").insert(0, "hello");
136+
const bytes = a.exportSnapshot();
137+
const b = Loro.fromSnapshot(bytes);
138+
b.getText("text").insert(0, "123");
139+
expect(b.toJson()).toStrictEqual({ "text": "123hello" })
140+
})
132141
});
133142

134143
describe("map", () => {

0 commit comments

Comments
 (0)