Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(web): normalize whitespace before setting document titles (#9441)

Frezcd6517309870a
diff --git a/apps/web/platform/document-title.test.tsx b/apps/web/platform/document-title.test.tsx
index 5b7c9b0ac9..262c0a2175 100644
--- a/apps/web/platform/document-title.test.tsx
+++ b/apps/web/platform/document-title.test.tsx
@@ -52,6 +52,28 @@ describe("formatDocumentTitle", () => {
);
});
+ it("normalizes HTML ASCII whitespace before clipping the page name", () => {
+ expect(formatDocumentTitle(" Chat\t\n\f\r question ")).toBe(
+ "Chat question | Multica",
+ );
+ expect(formatDocumentTitle(`Chat${"\n".repeat(MAX_PAGE_TITLE_LENGTH)}question`)).toBe(
+ "Chat question | Multica",
+ );
+ });
+
+ it("round-trips through document.title without changing the intended value", () => {
+ const formatted = formatDocumentTitle("Why did this fail?\n\nhttps://example.test/issue");
+ document.title = formatted;
+
+ expect(document.title).toBe(formatted);
+ });
+
+ it("preserves non-ASCII spaces within the page name", () => {
+ expect(formatDocumentTitle("Chat\u00a0\u2003question")).toBe(
+ "Chat\u00a0\u2003question | Multica",
+ );
+ });
+
it("falls back to the site title rather than a bare suffix", () => {
expect(formatDocumentTitle("")).toBe(SITE_TITLE);
expect(formatDocumentTitle(" ")).toBe(SITE_TITLE);
diff --git a/apps/web/platform/document-title.ts b/apps/web/platform/document-title.ts
index 114b37f6de..b1402bd17c 100644
--- a/apps/web/platform/document-title.ts
+++ b/apps/web/platform/document-title.ts
@@ -54,7 +54,9 @@ function clipTitle(title: string): string {
* rendering a bare ` | Multica`.
*/
export function formatDocumentTitle(pageTitle: string | null | undefined): string {
- const trimmed = pageTitle?.trim();
+ // Match document.title's ASCII whitespace folding so the title observer
+ // compares the same value the browser reads back after a write.
+ const trimmed = pageTitle?.replace(/[\t\n\f\r ]+/g, " ").trim();
if (!trimmed) return SITE_TITLE;
return `${clipTitle(trimmed)}${TITLE_SUFFIX}`;
}