Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Skip reloading editors without a loaded document https://github.com/siyuan-note/siyuan/issues/19297

Daniel6cad093273a1
diff --git a/app/src/protyle/util/reload.ts b/app/src/protyle/util/reload.ts
index f9b3df9703..09c5c86b4e 100644
--- a/app/src/protyle/util/reload.ts
+++ b/app/src/protyle/util/reload.ts
@@ -11,8 +11,12 @@ import {hideKeyboardToolbar} from "../../mobile/util/keyboardToolbar";
import {restoreLuteMarkdownSyntax} from "./paste";
import {invalidateTrackedRanges} from "./trackedRange";
import {updateBacklinkReferenceVisibility} from "../wysiwyg/backlinkReference";
+import {shouldReloadProtyle} from "./reloadState";
export const reloadProtyle = (protyle: IProtyle, focus: boolean, updateReadonly?: boolean) => {
+ if (!shouldReloadProtyle(protyle)) {
+ return;
+ }
updateBacklinkReferenceVisibility(protyle);
invalidateTrackedRanges(protyle);
/// #if MOBILE
diff --git a/app/src/protyle/util/reloadState.test.ts b/app/src/protyle/util/reloadState.test.ts
new file mode 100644
index 0000000000..5c8509296c
--- /dev/null
+++ b/app/src/protyle/util/reloadState.test.ts
@@ -0,0 +1,23 @@
+import {describe, it} from "node:test";
+import * as assert from "node:assert/strict";
+import {shouldReloadProtyle} from "./reloadState";
+
+describe("shouldReloadProtyle", () => {
+ it("skips an editor that has not loaded a document", () => {
+ assert.equal(shouldReloadProtyle({block: {}, options: {}}), false);
+ });
+
+ it("reloads an editor that has loaded a document", () => {
+ assert.equal(shouldReloadProtyle({
+ block: {rootID: "20240101120000-abcdefg"},
+ options: {},
+ }), true);
+ });
+
+ it("reloads a backlink editor without a loaded document", () => {
+ assert.equal(shouldReloadProtyle({
+ block: {},
+ options: {backlinkData: []},
+ }), true);
+ });
+});
diff --git a/app/src/protyle/util/reloadState.ts b/app/src/protyle/util/reloadState.ts
new file mode 100644
index 0000000000..522e2ca2bb
--- /dev/null
+++ b/app/src/protyle/util/reloadState.ts
@@ -0,0 +1,2 @@
+export const shouldReloadProtyle = (protyle: Pick<IProtyle, "block" | "options">) =>
+ Boolean(protyle.block.rootID || protyle.options.backlinkData);