Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

fix(web): stop the tab title loop on titles with extra whitespace (#722)

Ken73aadf9945ec
diff --git a/apps/web/src/hooks/useDocumentTitle.test.tsx b/apps/web/src/hooks/useDocumentTitle.test.tsx
index 829d500a..1f3eabfe 100644
--- a/apps/web/src/hooks/useDocumentTitle.test.tsx
+++ b/apps/web/src/hooks/useDocumentTitle.test.tsx
@@ -93,6 +93,11 @@ describe('useDocumentTitle', () => {
await render({ section: 'Acme', page: 'Acme › New' });
assert.equal(document.title, 'Acme › New');
});
+
+ it('settles on a title with extra whitespace', async () => {
+ await render({ section: 'Acme', page: ' ACME-1 Fix ' });
+ assert.equal(document.title, 'ACME-1 Fix');
+ });
});
describe('titlePath', () => {
diff --git a/apps/web/src/hooks/useDocumentTitle.ts b/apps/web/src/hooks/useDocumentTitle.ts
index a8d05b86..3581d5ff 100644
--- a/apps/web/src/hooks/useDocumentTitle.ts
+++ b/apps/web/src/hooks/useDocumentTitle.ts
@@ -18,7 +18,9 @@ let observedHead: HTMLHeadElement | null = null;
function apply() {
let top: Entry | null = null;
for (const entry of entries) if (!top || entry.rank >= top.rank) top = entry;
- const title = top?.title ?? APP_NAME;
+ // The browser trims and collapses whitespace in document.title; match it, or the
+ // comparison below never holds and the head observer loops forever.
+ const title = (top?.title ?? APP_NAME).replace(/[\t\n\f\r ]+/g, ' ').trim();
if (window.document.title !== title) window.document.title = title;
// Next streams the metadata, and React can insert its <title> into the head after
// a page has set its own; the browser shows the first one, so the title is set again.