diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs index 549852fb8..290c4e02b 100644 --- a/crates/doc/src/lib.rs +++ b/crates/doc/src/lib.rs @@ -396,9 +396,18 @@ impl Document { /// Replace the document's raw node map and `next_id` counter (used by compact format loaders /// before [`Self::validate`] / [`Self::repair`]). + /// + /// On a fresh single-user document (`client_id() == 0`) the saved `next_id` is preserved; on a + /// document bound to a collaboration client the counter is normalized into that client's ID + /// space so [`Self::alloc_id`] never emits cross-client IDs. pub fn set_raw_nodes(&mut self, nodes: impl IntoIterator)>, next_id: NodeId) { self.nodes = nodes.into_iter().map(|(id, node)| (id, NodeArc(node))).collect(); - self.next_id.next = next_id.0; + let client = self.next_id.client; + if client == 0 { + self.next_id.next = next_id.0; + } else { + self.set_client_id(client); + } self.dirty = Dirty::default(); } diff --git a/crates/format/src/compact/decode.rs b/crates/format/src/compact/decode.rs index 9c8329ef3..d7fb1f2d7 100644 --- a/crates/format/src/compact/decode.rs +++ b/crates/format/src/compact/decode.rs @@ -63,6 +63,7 @@ struct CompactDocWire { kind: FileKind, pages: Vec, nodes: BTreeMap, + nodes_parsed_bytes: usize, vectors_raw: Option, next_id: NodeId, styles: Vec