UndoManager: batch imports clear undo history

オープン
#1,298 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, rust
領域
data

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Rust
スター
6.3k
フォーク
205
平均マージ
3日 18時間
マージ済み PR(30日)
45

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

loro-dev/loro のほかの issue

loro-dev/loro の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。