Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-7877: fix(web): keep workspace document titles authoritative (#9067)
Zhexuan Yang3c8c60485225
diff --git a/apps/web/platform/document-title.test.tsx b/apps/web/platform/document-title.test.tsxindex fa2b56f64a..5b7c9b0ac9 100644--- a/apps/web/platform/document-title.test.tsx+++ b/apps/web/platform/document-title.test.tsx@@ -8,7 +8,7 @@* navigation behavior of `document.title`.*/import { describe, expect, it, vi, beforeEach } from "vitest";-import { render } from "@testing-library/react";+import { render, waitFor } from "@testing-library/react";const route = vi.hoisted(() => ({ pathname: "/acme/issues", search: "" }));vi.mock("next/navigation", () => ({@@ -138,4 +138,42 @@ describe("WorkspaceDocumentTitle", () => {expect(document.title).toBe("Inbox | Multica");});+ it("restores the workspace title when route metadata overwrites it", async () => {+ open("/acme/issues/MUL-123");+ presentation.title = "MUL-123: Fix login";+ render(<WorkspaceDocumentTitle />);++ document.title = SITE_TITLE;++ await waitFor(() => {+ expect(document.title).toBe("MUL-123: Fix login | Multica");+ });+ });+ it("updates when navigating from one issue to another", () => {+ open("/acme/issues/HIBE-63");+ presentation.title = "HIBE-63: First issue";+ const view = render(<WorkspaceDocumentTitle />);+ expect(document.title).toBe("HIBE-63: First issue | Multica");++ open("/acme/issues/HIBE-64");+ presentation.title = "HIBE-64: Second issue";+ view.rerender(<WorkspaceDocumentTitle />);++ expect(document.title).toBe("HIBE-64: Second issue | Multica");+ });++ it("restores the latest issue after metadata overwrites a later navigation", async () => {+ open("/acme/issues/HIBE-63");+ presentation.title = "HIBE-63: First issue";+ const view = render(<WorkspaceDocumentTitle />);++ open("/acme/issues/HIBE-64");+ presentation.title = "HIBE-64: Second issue";+ view.rerender(<WorkspaceDocumentTitle />);+ document.title = SITE_TITLE;++ await waitFor(() => {+ expect(document.title).toBe("HIBE-64: Second issue | Multica");+ });+ });});diff --git a/apps/web/platform/workspace-document-title.tsx b/apps/web/platform/workspace-document-title.tsxindex 6e989490e4..07d215000a 100644--- a/apps/web/platform/workspace-document-title.tsx+++ b/apps/web/platform/workspace-document-title.tsx@@ -1,6 +1,6 @@"use client";-import { useEffect, useMemo } from "react";+import { useEffect, useMemo, useRef } from "react";import { usePathname, useSearchParams } from "next/navigation";import { parseTabSubject } from "@multica/core/paths";import { useTabPresentation } from "@multica/views/layout";@@ -38,14 +38,26 @@ export function WorkspaceDocumentTitle() {// tab strip needs: a browser tab has no other place to show the product name.const documentTitle =subject.kind === "unknown" ? SITE_TITLE : formatDocumentTitle(title);+ const documentTitleRef = useRef(documentTitle);+ documentTitleRef.current = documentTitle;- // `url` is a dependency even though `documentTitle` is what we write: an app- // router navigation re-renders the target route's metadata and resets- // document.title to the root default, so a move between two routes that- // happen to share a title (`/inbox` → `/inbox?view=archived`) has to- // re-assert it.+ // Keep one observer for the dashboard lifetime and have it read the latest+ // intended title from a ref. Recreating an observer per route leaves a window+ // where a queued callback from the previous issue can restore its stale title.useEffect(() => {- document.title = documentTitle;+ const applyLatestTitle = () => {+ const latest = documentTitleRef.current;+ if (document.title !== latest) document.title = latest;+ };++ const observer = new MutationObserver(applyLatestTitle);+ observer.observe(document.head, { childList: true, subtree: true });++ return () => observer.disconnect();+ }, []);++ useEffect(() => {+ if (document.title !== documentTitle) document.title = documentTitle;}, [documentTitle, url]);// Leaving the dashboard entirely (logout, workspace switcher, landing) drops