Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(print): inline the document title assignment
Elian Dorand58b975c454d
diff --git a/apps/client/src/print.spec.tsx b/apps/client/src/print.spec.tsxindex 0dfd4482fe..7dd235b5b6 100644--- a/apps/client/src/print.spec.tsx+++ b/apps/client/src/print.spec.tsx@@ -24,14 +24,7 @@ vi.mock("./widgets/collections/NoteList", () => ({}}));-import {- App,- applyPrintDocumentTitle,- Error404,- loadCustomCss,- main,- SingleNoteRenderer-} from "./print";+import { App, Error404, loadCustomCss, main, SingleNoteRenderer } from "./print";import froca from "./services/froca";import { buildNote } from "./test/easy-froca";@@ -240,8 +233,6 @@ describe("main", () => {expect(document.head.querySelector('link[href="api/fonts"]')).toBeTruthy();const titles = [...document.body.querySelectorAll("h1")].map((el) => el.textContent);expect(titles).toContain("Main Note");- // Regression (#11140): the exported PDF's metadata title follows the note, not the- // app shell default the print window inherits.expect(document.title).toBe("Main Note");});@@ -257,21 +248,3 @@ describe("main", () => {expect(document.body.querySelectorAll("h1").length).toBeGreaterThan(0);});});--describe("applyPrintDocumentTitle", () => {- const originalTitle = document.title;-- afterEach(() => {- document.title = originalTitle;- });-- it("keeps the inherited title when no note loaded", () => {- document.title = "Trilium Notes";-- applyPrintDocumentTitle(null);- applyPrintDocumentTitle(undefined);- applyPrintDocumentTitle({ title: "" });-- expect(document.title).toBe("Trilium Notes");- });-});diff --git a/apps/client/src/print.tsx b/apps/client/src/print.tsxindex fcb5040d8f..3be1851774 100644--- a/apps/client/src/print.tsx+++ b/apps/client/src/print.tsx@@ -49,24 +49,16 @@ export async function main() {const note = await froca.getNote(noteId);- applyPrintDocumentTitle(note);+ // printToPDF() and the browser print dialog name the document after document.title.+ if (note?.title) {+ document.title = note.title;+ }const bodyWrapper = document.createElement("div");render(<App note={note} noteId={noteId} />, bodyWrapper);document.body.appendChild(bodyWrapper);}-/**- * Why (#11140): `printToPDF()` and the browser print dialog take the exported document's- * metadata title from `document.title`; the print window inherits the app shell's- * "Trilium Notes" default, so every export announced itself as that instead of the note.- */-export function applyPrintDocumentTitle(note: { title: string } | null | undefined): void {- if (note?.title) {- document.title = note.title;- }-}-export function App({ note, noteId }: { note: FNote | null | undefined, noteId: string }) {const sentReadyEvent = useRef(false);const onProgressChanged = useCallback((progress: number) => {