Skip to content

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

:bug: Render calendar views without a date field https://github.com/siyuan-note/siyuan/issues/19795

Danielaa7deeb8d448
diff --git a/app/src/protyle/render/av/calendar/render.test.ts b/app/src/protyle/render/av/calendar/render.test.ts
new file mode 100644
index 0000000000..ba64f07071
--- /dev/null
+++ b/app/src/protyle/render/av/calendar/render.test.ts
@@ -0,0 +1,42 @@
+import * as assert from "node:assert/strict";
+import {readFileSync} from "node:fs";
+import {join} from "node:path";
+import {test} from "node:test";
+import {runInNewContext} from "node:vm";
+import {transpileModule, ModuleKind, ScriptTarget} from "typescript";
+import * as dates from "./date";
+
+test("calendar without a date field renders its setup instead of reading an absent undated cache", async () => {
+ const range = {start: new Date(2026, 8, 1).getTime(), end: new Date(2026, 8, 8).getTime(), timeZone: "UTC"};
+ const state = {anchor: range.start, mode: "month", rowLimit: 3};
+ const complete = new Error("container rendered");
+ let html = "";
+ const exports = {} as typeof import("./render");
+ const modules: Record<string, unknown> = {
+ "./date": dates,
+ "./state": {getCalendarState: () => state, getCalendarRequestRange: () => range},
+ "./settings": {getCalendarSettingsHTML: () => "date-field-settings"},
+ "../render": {genTabHeaderHTML: () => "view-switcher"},
+ "../col": {getColNameByType: (type: string) => type},
+ "../../../../util/escape": {escapeAttr: String, escapeHtml: String},
+ "../../../../constants": {Constants: {ZWSP: ""}},
+ "../container": {replaceAVContainer: (_block: unknown, value: string) => {
+ html = value;
+ throw complete;
+ }},
+ };
+ runInNewContext(transpileModule(readFileSync(join(__dirname, "render.ts"), "utf8"), {
+ compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2020},
+ }).outputText, {
+ exports, require: (name: string) => modules[name] || {},
+ window: {siyuan: {config: {lang: "en"}, languages: {calendarSelectDateField: "Select date field"}}},
+ document: {activeElement: null},
+ });
+ await assert.rejects(exports.renderCalendar({querySelector: (): null => null, removeAttribute() {}} as unknown as HTMLElement,
+ {options: {}} as IProtyle,
+ {viewID: "calendar", view: {calendar: {}, columns: [], rows: [], calendarRange: range}} as unknown as IAV),
+ error => error === complete);
+ assert.match(html, /view-switcher/);
+ assert.match(html, /Select date field/);
+ assert.match(html, /date-field-settings/);
+});
diff --git a/app/src/protyle/render/av/calendar/render.ts b/app/src/protyle/render/av/calendar/render.ts
index 9bdd21ec4c..e3590c2126 100644
--- a/app/src/protyle/render/av/calendar/render.ts
+++ b/app/src/protyle/render/av/calendar/render.ts
@@ -355,7 +355,7 @@ export const renderCalendar = async (blockElement: HTMLElement, protyle: IProtyl
const search = blockElement.querySelector<HTMLElement>('[data-type="av-search"]');
const query = search?.textContent || "";
const isSearching = search === document.activeElement;
- const hasUndated = state.undatedCount?.dateKeyID === dateColumn?.id && state.undatedCount.query === query.trim() &&
+ const hasUndated = !!dateColumn && state.undatedCount?.dateKeyID === dateColumn.id && state.undatedCount.query === query.trim() &&
state.undatedCount.total > 0;
const events: ICalendarEvent[] = [];
view.rows.forEach((row, rowIndex) => {