Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(navigation): resolve scene title on hidden background tabs (#61987)

Adam Leith78f75835037a
diff --git a/frontend/src/layout/navigation/Breadcrumbs/breadcrumbsLogic.test.ts b/frontend/src/layout/navigation/Breadcrumbs/breadcrumbsLogic.test.ts
index 7f7b0c032f38..c3f9891e42fc 100644
--- a/frontend/src/layout/navigation/Breadcrumbs/breadcrumbsLogic.test.ts
+++ b/frontend/src/layout/navigation/Breadcrumbs/breadcrumbsLogic.test.ts
@@ -56,7 +56,9 @@ describe('breadcrumbsLogic', () => {
expect(global.document.title).toEqual('Dashboards • PostHog')
})
- it('does not update the default document.title while hidden during startup', async () => {
+ it('resolves the title of a hidden tab the user has never looked at', async () => {
+ // A freshly-loaded background tab (duplicated tab, restored session, cmd+click) should
+ // settle on its scene title even while hidden, so it's identifiable in the tab strip.
global.document.title = 'PostHog'
Object.defineProperty(document, 'visibilityState', { configurable: true, value: 'hidden', writable: true })
@@ -65,11 +67,19 @@ describe('breadcrumbsLogic', () => {
router.actions.push(urls.savedInsights())
await expectLogic(logic).delay(1).toMatchValues({ documentTitle: 'Product analytics • PostHog' })
- expect(global.document.title).toEqual('PostHog')
+ expect(global.document.title).toEqual('Product analytics • PostHog')
+ // Once the user has focused the tab, later hidden updates are deferred (Chrome keepalive).
Object.defineProperty(document, 'visibilityState', { configurable: true, value: 'visible', writable: true })
document.dispatchEvent(new Event('visibilitychange'))
+ Object.defineProperty(document, 'visibilityState', { configurable: true, value: 'hidden', writable: true })
+ router.actions.push(urls.dashboards())
+ await expectLogic(logic).delay(1).toMatchValues({ documentTitle: 'Dashboards • PostHog' })
expect(global.document.title).toEqual('Product analytics • PostHog')
+
+ Object.defineProperty(document, 'visibilityState', { configurable: true, value: 'visible', writable: true })
+ document.dispatchEvent(new Event('visibilitychange'))
+ expect(global.document.title).toEqual('Dashboards • PostHog')
})
})
diff --git a/frontend/src/layout/navigation/Breadcrumbs/breadcrumbsLogic.tsx b/frontend/src/layout/navigation/Breadcrumbs/breadcrumbsLogic.tsx
index e4d2703c715e..f3ca0e9c25ff 100644
--- a/frontend/src/layout/navigation/Breadcrumbs/breadcrumbsLogic.tsx
+++ b/frontend/src/layout/navigation/Breadcrumbs/breadcrumbsLogic.tsx
@@ -208,12 +208,20 @@ export const breadcrumbsLogic = kea<breadcrumbsLogicType>([
})),
afterMount(({ cache }) => {
cache.syncTitle = (): void => {
+ const isVisible = document.visibilityState === 'visible'
+ if (isVisible) {
+ cache.hasBeenVisible = true
+ }
if (cache.desiredTitle == null || document.title === cache.desiredTitle) {
return
}
- // Chrome treats background title updates as a reason to keep a tab alive,
- // so we always defer syncing until the page is visible again.
- if (document.visibilityState === 'visible') {
+ // Chrome treats background title updates as a reason to keep a tab alive, so we
+ // defer syncing while hidden — except for a tab the user has never looked at yet
+ // (duplicated tab, restored session, cmd+click). That tab is still settling on its
+ // title and should reflect the scene so it's identifiable in the strip. The keepalive
+ // abuse case is a tab that was viewed then churns its title in the background, which
+ // this still defers.
+ if (isVisible || !cache.hasBeenVisible) {
document.title = cache.desiredTitle
}
}