UndoManager: batch imports clear undo history

Aperta
#1,298 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, rust
Ambito
data

Direzione di ricerca

Start in crates/loro-internal/src/loro.rs at import_batch (~L4099) and follow BatchImportGuard::finish, which reattaches via _checkout_to_latest_without_commit and emits EventTriggerKind::Checkout; UndoManager in crates/loro-internal/src/undo.rs clears both stacks on that event. The unused _checkout_to_latest_without_commit_as_import (~L2900) emits Import instead, so compare the two paths before wiring one in. Turn the JS repro into a failing test (canUndo() stays true after importBatch, undo() yields "RS"), then confirm separate import() calls still behave the same.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

versions: [email protected]. broken on 1.16.2, 1.10.0 and 1.5.0.

  1. Local inserts "L" and commits. canUndo() is true
  2. Remote makes two commits, "R" and "S", exported as two update blobs
  3. Local imports them with importBatch([first, second])
  4. The text is "LRS", correct, but canUndo() is now false and undo() does nothing

repro:

const { LoroDoc, UndoManager } = require("loro-crdt");

const local = new LoroDoc();
local.setPeerId("1");
const remote = new LoroDoc();
remote.setPeerId("2");
const undo = new UndoManager(local, { mergeInterval: 0 });

local.getText("t").insert(0, "L");
local.commit();
console.log(undo.canUndo()); // true

const blobs = [];
for (const c of ["R", "S"]) {
  const vv = remote.oplogVersion();
  remote.getText("t").insert(remote.getText("t").length, c);
  remote.commit();
  blobs.push(remote.export({ mode: "update", from: vv }));
}

local.importBatch(blobs);
console.log(local.getText("t").toString()); // "LRS"
console.log(undo.canUndo()); // false
console.log(undo.undo()); // false

expected: canUndo() is still true and undo removes "L", giving "RS", like two separate import() calls
actual: the undo stack is wiped

impl: for 2+ blobs, import_batch force-detaches, imports, then reattaches in BatchImportGuard::finish via _checkout_to_latest_without_commit, which emits EventTriggerKind::Checkout. UndoManager clears both stacks on Checkout. There's already a _checkout_to_latest_without_commit_as_import that emits Import, but nothing calls it

Lingua principale
Rust
Stelle
6.3k
Fork
205
Merge medio
3g 18h
PR unite (30g)
45

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di loro-dev/loro

Tutte le issue di loro-dev/loro

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.