Skip to content

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

:bug: Preserve window layout saving after restoring empty tabs https://github.com/siyuan-note/siyuan/issues/19891

Daniela1b6136ce23c
diff --git a/app/src/window/setHeader.test.ts b/app/src/window/setHeader.test.ts
new file mode 100644
index 0000000000..af17f4dbaf
--- /dev/null
+++ b/app/src/window/setHeader.test.ts
@@ -0,0 +1,26 @@
+import * as assert from "node:assert/strict";
+import {readFileSync} from "node:fs";
+import {test} from "node:test";
+import {runInNewContext} from "node:vm";
+import {ModuleKind, transpileModule} from "typescript";
+
+test("空页签不阻断新窗口初始化,重新添加文档后更新窗口标识", () => {
+ const tabs: Array<{model?: unknown, headElement?: {getAttribute: () => string}}> = [{}];
+ const window = {location: {hash: "previous"}};
+ const api = {} as typeof import("./setHeader");
+ const dependencies = {
+ isWindow: () => true,
+ getAllTabs: () => tabs,
+ Constants: {ZWSP: "\u200b"},
+ Editor: class {},
+ Asset: class {},
+ };
+ runInNewContext(transpileModule(readFileSync("src/window/setHeader.ts", "utf8"), {
+ compilerOptions: {module: ModuleKind.CommonJS},
+ }).outputText, {exports: api, require: () => dependencies, window});
+ api.setModelsHash();
+ assert.equal(window.location.hash, "");
+ tabs.push({headElement: {getAttribute: () => JSON.stringify({instance: "Editor", rootId: "reopened"})}});
+ api.setModelsHash();
+ assert.equal(window.location.hash, "reopened\u200b");
+});
diff --git a/app/src/window/setHeader.ts b/app/src/window/setHeader.ts
index 1efe766030..17c966c6f9 100644
--- a/app/src/window/setHeader.ts
+++ b/app/src/window/setHeader.ts
@@ -11,7 +11,7 @@ export const setModelsHash = () => {
let hash = "";
getAllTabs().forEach(tab => {
if (!tab.model) {
- const initTab = tab.headElement.getAttribute("data-initdata");
+ const initTab = tab.headElement?.getAttribute("data-initdata");
if (initTab) {
const initTabData = JSON.parse(initTab);
if (initTabData.instance === "Editor") {