From 701d5f320f37733071150dd0f78201f3bf7bfdc9 Mon Sep 17 00:00:00 2001 From: Eder is a nobody Date: Wed, 16 Apr 2025 02:28:03 +0800 Subject: [PATCH] fix: add try/finally block in withoutSaving method to ensure state restoration (#5837) Co-authored-by: ederjiang --- .changeset/rotten-poems-collect.md | 5 +++++ packages/slate-history/src/history-editor.ts | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .changeset/rotten-poems-collect.md diff --git a/.changeset/rotten-poems-collect.md b/.changeset/rotten-poems-collect.md new file mode 100644 index 000000000..475c64370 --- /dev/null +++ b/.changeset/rotten-poems-collect.md @@ -0,0 +1,5 @@ +--- +'slate-history': patch +--- + +fix: add try/finally block in withoutSaving method to ensure state restoration diff --git a/packages/slate-history/src/history-editor.ts b/packages/slate-history/src/history-editor.ts index d2f49670b..264ec1135 100644 --- a/packages/slate-history/src/history-editor.ts +++ b/packages/slate-history/src/history-editor.ts @@ -120,7 +120,10 @@ export const HistoryEditor = { withoutSaving(editor: HistoryEditor, fn: () => void): void { const prev = HistoryEditor.isSaving(editor) SAVING.set(editor, false) - fn() - SAVING.set(editor, prev) + try { + fn() + } finally { + SAVING.set(editor, prev) + } }, }