From 5e53e8ec0e1595c23e6bb2f8925e0bba6c16bb85 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 27 Nov 2026 19:21:04 +1100 Subject: [PATCH] fix(ui): keep the tab title until the route resolves (#2115) Opening a page by URL showed "Page not found" in the tab while the router was still at its start location, which carries no label, so the not-found copy stood in for the page for as long as the resolution took. The title is now written only once the router has resolved the address, and the rule lives in ui/src/lib/page-title.ts so the start location's silence is tested. --- ui/src/App.vue | 9 +++++++-- ui/src/lib/page-title.ts | 19 +++++++++++++++++++ ui/test/page-title.test.ts | 21 +++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 ui/src/lib/page-title.ts create mode 100644 ui/test/page-title.test.ts diff --git a/ui/src/App.vue b/ui/src/App.vue index 7fd2e3ec6..5d1fb640e 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -23,6 +23,7 @@ import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar"; import { layoutComponent, resolveLayout } from "@/layouts"; import { TooltipProvider } from "@/components/ui/tooltip"; import { hiddenPaths, navTree } from "@/lib/nav"; +import { pageTitle } from "@/lib/page-title"; import { useSessionStore } from "@/stores/session"; import { Toaster } from "vue-sonner"; import "vue-sonner/style.css"; @@ -62,9 +63,13 @@ watch([() => route.path, hidden], () => { const first = navTree(hidden.value).flatMap((node) => (node.kind === "link" ? [node.entry] : node.items))[0]; void router.replace(first ? first.path : "/account"); }); -watch(() => [route.path, accounts.instance], () => { +// The tab keeps the served page's title until the router has resolved the +// address the browser opened: writing one for the start location reads as a +// missing page for as long as that takes. +watch(() => [route.path, accounts.instance, routerReady.value], () => { const scope = route.meta.org ? "Organisation" : route.meta.settings ? "Instance" : ""; - document.title = [route.meta.label || errors.base.notFound.title, scope, "Archie", accounts.instance].filter(Boolean).join(" | "); + const title = pageTitle(routerReady.value, typeof route.meta.label === "string" ? route.meta.label : "", scope, accounts.instance ?? "", errors.base.notFound.title); + if (title) document.title = title; }, { immediate: true }); // A page load keeps focus at the top so the skip link is the first keyboard // stop; later navigations move focus to the new page. diff --git a/ui/src/lib/page-title.ts b/ui/src/lib/page-title.ts new file mode 100644 index 000000000..ecce98021 --- /dev/null +++ b/ui/src/lib/page-title.ts @@ -0,0 +1,19 @@ +/** + * The browser tab's title for the page on screen. + * + * The router is still at its start location until it has resolved the address + * the browser opened, and that location carries no page label. Writing the + * title then reads as a missing page for as long as the resolution takes, so an + * unresolved route writes no title at all and the tab keeps the one the served + * page came with. + */ +export function pageTitle( + resolved: boolean, + label: string, + scope: string, + instance: string, + missing: string, +): string { + if (!resolved) return ""; + return [label || missing, scope, "Archie", instance].filter(Boolean).join(" | "); +} diff --git a/ui/test/page-title.test.ts b/ui/test/page-title.test.ts new file mode 100644 index 000000000..bdd79231e --- /dev/null +++ b/ui/test/page-title.test.ts @@ -0,0 +1,21 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import { pageTitle } from "../src/lib/page-title.ts"; + +const MISSING = "Page not found"; + +// Guards #2115: opening a dashboard page by URL showed "Page not found" in the +// tab until the router resolved the address, because the start location has no +// label and the not-found copy stood in for it. +test("an unresolved route writes no title", () => { + assert.equal(pageTitle(false, "", "", "archie", MISSING), ""); +}); + +test("a resolved route names its page", () => { + assert.equal(pageTitle(true, "Models", "Instance", "carina", MISSING), "Models | Instance | Archie | carina"); +}); + +test("a resolved route with no page is the one that reads as not found", () => { + assert.equal(pageTitle(true, "", "", "carina", MISSING), "Page not found | Archie | carina"); +});