From b69d25b6564b9cc522c0bf39340f341ae7bcb6f1 Mon Sep 17 00:00:00 2001 From: arj22 Date: Wed, 30 Sep 2026 08:19:12 -0500 Subject: [PATCH 01/20] feat: add optional NEXT_PUBLIC_INSTANCE_LABEL suffix to brand name Lets operators running multiple HyperDX instances append a short label to the brand name (e.g. "HyperDX UK") wherever it's shown, via an opt-in env var. No-op when unset. Co-Authored-By: Claude Sonnet 5 --- .changeset/instance-label-brand-name.md | 7 +++++++ packages/app/src/config.ts | 3 +++ packages/app/src/theme/ThemeProvider.tsx | 6 +++++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/instance-label-brand-name.md diff --git a/.changeset/instance-label-brand-name.md b/.changeset/instance-label-brand-name.md new file mode 100644 index 0000000000..b308a4010d --- /dev/null +++ b/.changeset/instance-label-brand-name.md @@ -0,0 +1,7 @@ +--- +'@hyperdx/app': patch +--- + +feat: add optional `NEXT_PUBLIC_INSTANCE_LABEL` suffix to the brand name + +Operators running multiple HyperDX instances (e.g. one per region) can now set `NEXT_PUBLIC_INSTANCE_LABEL` to append a short label to the brand name everywhere it's shown (browser tab titles, sidebar, etc.), e.g. "HyperDX UK". Empty by default, no behavior change if unset. diff --git a/packages/app/src/config.ts b/packages/app/src/config.ts index 755d6f5762..c91e3ca775 100644 --- a/packages/app/src/config.ts +++ b/packages/app/src/config.ts @@ -82,6 +82,9 @@ export const IS_METRICS_ENABLED = true; export const IS_MTVIEWS_ENABLED = false; export const IS_SESSIONS_ENABLED = true; export const IS_PROMQL_ENABLED = env('NEXT_PUBLIC_ENABLE_PROMQL') === 'true'; +// Optional suffix appended to the brand name (e.g. "HyperDX UK"), for +// operators running multiple instances. Empty by default. +export const INSTANCE_LABEL = env('NEXT_PUBLIC_INSTANCE_LABEL') ?? ''; // Alert detail page (/alerts/:id). Default off — currently enabled only in // dev (.env.development) and CI (e2e webserver) while the feature bakes. export const IS_ALERT_DETAILS_ENABLED = diff --git a/packages/app/src/theme/ThemeProvider.tsx b/packages/app/src/theme/ThemeProvider.tsx index 071601dfa9..b73b9ee2d5 100644 --- a/packages/app/src/theme/ThemeProvider.tsx +++ b/packages/app/src/theme/ThemeProvider.tsx @@ -8,6 +8,8 @@ import React, { useState, } from 'react'; +import { INSTANCE_LABEL } from '@/config'; + import { DEFAULT_THEME, getDevThemeName, @@ -239,5 +241,7 @@ export function useThemeName(): ThemeName { /** Hook to get the current theme's display name for UI copy (e.g. "HyperDX" or "ClickStack"). */ export function useBrandDisplayName(): string { const { theme } = useAppTheme(); - return theme.displayName; + return INSTANCE_LABEL + ? `${theme.displayName} ${INSTANCE_LABEL}` + : theme.displayName; } From a54727f5cb44be1cdf999b17ebfeb4023497d949 Mon Sep 17 00:00:00 2001 From: arj22 Date: Wed, 30 Sep 2026 08:36:23 -0500 Subject: [PATCH 02/20] fix: scope instance label to tab title only, not brand copy useBrandDisplayName() is used for general UI copy (errors, CSV filenames, marketing text), not just titles, so appending the instance label there leaked it into unrelated places. Move the label into a dedicated useInstanceLabelTitle() hook that patches the tab title via a MutationObserver, mounted once in _app.tsx, so every page gets it without per-page changes. Co-Authored-By: Claude Sonnet 5 --- .changeset/instance-label-brand-name.md | 4 +-- docker-compose.yml | 3 ++ packages/app/pages/_app.tsx | 2 ++ packages/app/src/config.ts | 6 ++-- .../useInstanceLabelTitle.no-label.test.tsx | 13 ++++++++ .../__tests__/useInstanceLabelTitle.test.tsx | 32 +++++++++++++++++++ .../app/src/hooks/useInstanceLabelTitle.ts | 31 ++++++++++++++++++ packages/app/src/theme/ThemeProvider.tsx | 6 +--- 8 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 packages/app/src/hooks/__tests__/useInstanceLabelTitle.no-label.test.tsx create mode 100644 packages/app/src/hooks/__tests__/useInstanceLabelTitle.test.tsx create mode 100644 packages/app/src/hooks/useInstanceLabelTitle.ts diff --git a/.changeset/instance-label-brand-name.md b/.changeset/instance-label-brand-name.md index b308a4010d..95d3c9c2dc 100644 --- a/.changeset/instance-label-brand-name.md +++ b/.changeset/instance-label-brand-name.md @@ -2,6 +2,6 @@ '@hyperdx/app': patch --- -feat: add optional `NEXT_PUBLIC_INSTANCE_LABEL` suffix to the brand name +feat: add optional `NEXT_PUBLIC_INSTANCE_LABEL` suffix to the browser tab title -Operators running multiple HyperDX instances (e.g. one per region) can now set `NEXT_PUBLIC_INSTANCE_LABEL` to append a short label to the brand name everywhere it's shown (browser tab titles, sidebar, etc.), e.g. "HyperDX UK". Empty by default, no behavior change if unset. +Operators running multiple HyperDX instances (e.g. one per region) can now set `NEXT_PUBLIC_INSTANCE_LABEL` to append a short label to the browser tab title, e.g. "HyperDX UK". Empty by default, no behavior change if unset. diff --git a/docker-compose.yml b/docker-compose.yml index ada6f5c0d9..8e1600d0f2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -87,6 +87,9 @@ services: # NEXT_PUBLIC_ENABLE_PROMQL: 'true' # Uncomment to enable the alert detail page (in development) # NEXT_PUBLIC_ENABLE_ALERT_DETAILS: 'true' + # Uncomment and set to append a label to the browser tab title, e.g. + # for operators running multiple instances (produces "HyperDX UK") + # NEXT_PUBLIC_INSTANCE_LABEL: 'UK' DEFAULT_CONNECTIONS: '[{"name":"Local ClickHouse","host":"http://ch-server:8123","username":"default","password":""}]' diff --git a/packages/app/pages/_app.tsx b/packages/app/pages/_app.tsx index 5102c68acc..3140e284f1 100644 --- a/packages/app/pages/_app.tsx +++ b/packages/app/pages/_app.tsx @@ -23,6 +23,7 @@ import { } from '@/config/fonts'; import { ibmPlexMono, inter, roboto, robotoMono } from '@/fonts'; import { fetchServerVersion, installHdxDebug } from '@/hdxDebug'; +import { useInstanceLabelTitle } from '@/hooks/useInstanceLabelTitle'; import { AppThemeProvider, useAppTheme } from '@/theme/ThemeProvider'; import { ThemeWrapper } from '@/ThemeWrapper'; import { NextApiConfigResponseData } from '@/types'; @@ -71,6 +72,7 @@ type AppPropsWithLayout = AppProps & { // Must be rendered inside AppThemeProvider to avoid hydration mismatch function AppHeadContent() { const { theme } = useAppTheme(); + useInstanceLabelTitle(); return ( diff --git a/packages/app/src/config.ts b/packages/app/src/config.ts index c91e3ca775..e7b21b4671 100644 --- a/packages/app/src/config.ts +++ b/packages/app/src/config.ts @@ -82,9 +82,9 @@ export const IS_METRICS_ENABLED = true; export const IS_MTVIEWS_ENABLED = false; export const IS_SESSIONS_ENABLED = true; export const IS_PROMQL_ENABLED = env('NEXT_PUBLIC_ENABLE_PROMQL') === 'true'; -// Optional suffix appended to the brand name (e.g. "HyperDX UK"), for -// operators running multiple instances. Empty by default. -export const INSTANCE_LABEL = env('NEXT_PUBLIC_INSTANCE_LABEL') ?? ''; +// Optional suffix appended to the browser tab title (e.g. "HyperDX UK"), +// for operators running multiple instances. Empty by default. +export const INSTANCE_LABEL = (env('NEXT_PUBLIC_INSTANCE_LABEL') ?? '').trim(); // Alert detail page (/alerts/:id). Default off — currently enabled only in // dev (.env.development) and CI (e2e webserver) while the feature bakes. export const IS_ALERT_DETAILS_ENABLED = diff --git a/packages/app/src/hooks/__tests__/useInstanceLabelTitle.no-label.test.tsx b/packages/app/src/hooks/__tests__/useInstanceLabelTitle.no-label.test.tsx new file mode 100644 index 0000000000..d9deea73c8 --- /dev/null +++ b/packages/app/src/hooks/__tests__/useInstanceLabelTitle.no-label.test.tsx @@ -0,0 +1,13 @@ +import { renderHook } from '@testing-library/react'; + +jest.mock('@/config', () => ({ INSTANCE_LABEL: '' })); + +import { useInstanceLabelTitle } from '@/hooks/useInstanceLabelTitle'; + +describe('useInstanceLabelTitle (INSTANCE_LABEL unset)', () => { + it('leaves the title untouched', () => { + document.title = 'Search - HyperDX'; + renderHook(() => useInstanceLabelTitle()); + expect(document.title).toBe('Search - HyperDX'); + }); +}); diff --git a/packages/app/src/hooks/__tests__/useInstanceLabelTitle.test.tsx b/packages/app/src/hooks/__tests__/useInstanceLabelTitle.test.tsx new file mode 100644 index 0000000000..c2da00a68e --- /dev/null +++ b/packages/app/src/hooks/__tests__/useInstanceLabelTitle.test.tsx @@ -0,0 +1,32 @@ +import { renderHook } from '@testing-library/react'; + +jest.mock('@/config', () => ({ INSTANCE_LABEL: 'UK' })); + +import { useInstanceLabelTitle } from '@/hooks/useInstanceLabelTitle'; + +describe('useInstanceLabelTitle', () => { + beforeEach(() => { + document.title = 'Search - HyperDX'; + }); + + it('appends the instance label to the current title', () => { + renderHook(() => useInstanceLabelTitle()); + expect(document.title).toBe('Search - HyperDX UK'); + }); + + it('keeps appending the label as the title changes on navigation', done => { + renderHook(() => useInstanceLabelTitle()); + document.title = 'Alerts - HyperDX'; + // MutationObserver callbacks are microtasks; flush before asserting. + queueMicrotask(() => { + expect(document.title).toBe('Alerts - HyperDX UK'); + done(); + }); + }); + + it('does not double-append if the title already has the suffix', () => { + document.title = 'Search - HyperDX UK'; + renderHook(() => useInstanceLabelTitle()); + expect(document.title).toBe('Search - HyperDX UK'); + }); +}); diff --git a/packages/app/src/hooks/useInstanceLabelTitle.ts b/packages/app/src/hooks/useInstanceLabelTitle.ts new file mode 100644 index 0000000000..993d29643b --- /dev/null +++ b/packages/app/src/hooks/useInstanceLabelTitle.ts @@ -0,0 +1,31 @@ +import { useEffect } from 'react'; + +import { INSTANCE_LABEL } from '@/config'; + +/** Appends INSTANCE_LABEL to the tab title via a MutationObserver, so every + * page gets it without each one needing its own change. */ +export function useInstanceLabelTitle(): void { + useEffect(() => { + if (!INSTANCE_LABEL) { + return; + } + const suffix = ` ${INSTANCE_LABEL}`; + const titleEl = document.querySelector('title'); + if (!titleEl) { + return; + } + const applySuffix = () => { + if (!document.title.endsWith(suffix)) { + document.title = `${document.title}${suffix}`; + } + }; + applySuffix(); + const observer = new MutationObserver(applySuffix); + observer.observe(titleEl, { + childList: true, + characterData: true, + subtree: true, + }); + return () => observer.disconnect(); + }, []); +} diff --git a/packages/app/src/theme/ThemeProvider.tsx b/packages/app/src/theme/ThemeProvider.tsx index b73b9ee2d5..071601dfa9 100644 --- a/packages/app/src/theme/ThemeProvider.tsx +++ b/packages/app/src/theme/ThemeProvider.tsx @@ -8,8 +8,6 @@ import React, { useState, } from 'react'; -import { INSTANCE_LABEL } from '@/config'; - import { DEFAULT_THEME, getDevThemeName, @@ -241,7 +239,5 @@ export function useThemeName(): ThemeName { /** Hook to get the current theme's display name for UI copy (e.g. "HyperDX" or "ClickStack"). */ export function useBrandDisplayName(): string { const { theme } = useAppTheme(); - return INSTANCE_LABEL - ? `${theme.displayName} ${INSTANCE_LABEL}` - : theme.displayName; + return theme.displayName; } From 9c76c833fedb97438bc30da58157d51cc458a957 Mon Sep 17 00:00:00 2001 From: arj22 Date: Wed, 30 Sep 2026 09:03:45 -0500 Subject: [PATCH 03/20] feat: also show instance label in sidebar wordmark, cap at 9 chars Greptile flagged that the sidebar wordmark still looked identical across labeled instances. Add the label next to the wordmark in AppNav.tsx directly (not the shared Wordmark.tsx component, which is also used by the public LandingHeader). Cap at 9 chars based on measuring the actual sidebar layout - longer labels crowd the collapse button. Co-Authored-By: Claude Sonnet 5 --- .changeset/instance-label-brand-name.md | 4 ++-- packages/app/src/__tests__/config.instanceLabel.test.ts | 9 +++++++++ packages/app/src/components/AppNav/AppNav.tsx | 7 ++++++- packages/app/src/config.ts | 7 ++++--- 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 packages/app/src/__tests__/config.instanceLabel.test.ts diff --git a/.changeset/instance-label-brand-name.md b/.changeset/instance-label-brand-name.md index 95d3c9c2dc..973b0d651f 100644 --- a/.changeset/instance-label-brand-name.md +++ b/.changeset/instance-label-brand-name.md @@ -2,6 +2,6 @@ '@hyperdx/app': patch --- -feat: add optional `NEXT_PUBLIC_INSTANCE_LABEL` suffix to the browser tab title +feat: add optional `NEXT_PUBLIC_INSTANCE_LABEL` suffix to the tab title and sidebar -Operators running multiple HyperDX instances (e.g. one per region) can now set `NEXT_PUBLIC_INSTANCE_LABEL` to append a short label to the browser tab title, e.g. "HyperDX UK". Empty by default, no behavior change if unset. +Operators running multiple HyperDX instances (e.g. one per region) can now set `NEXT_PUBLIC_INSTANCE_LABEL` to append a short label (max 9 chars) to the browser tab title and sidebar wordmark, e.g. "HyperDX UK". Empty by default, no behavior change if unset. diff --git a/packages/app/src/__tests__/config.instanceLabel.test.ts b/packages/app/src/__tests__/config.instanceLabel.test.ts new file mode 100644 index 0000000000..08836075ad --- /dev/null +++ b/packages/app/src/__tests__/config.instanceLabel.test.ts @@ -0,0 +1,9 @@ +jest.mock('next-runtime-env', () => ({ env: () => ' ExtraLongLabel ' })); + +import { INSTANCE_LABEL } from '@/config'; + +describe('INSTANCE_LABEL', () => { + it('trims whitespace and caps at 9 characters', () => { + expect(INSTANCE_LABEL).toBe('ExtraLong'); + }); +}); diff --git a/packages/app/src/components/AppNav/AppNav.tsx b/packages/app/src/components/AppNav/AppNav.tsx index 32ef55d9be..bcf329c233 100644 --- a/packages/app/src/components/AppNav/AppNav.tsx +++ b/packages/app/src/components/AppNav/AppNav.tsx @@ -30,7 +30,7 @@ import { import api from '@/api'; import { AlertStatusIcon } from '@/components/AlertStatusIcon'; -import { APP_VERSION, IS_LOCAL_MODE } from '@/config'; +import { APP_VERSION, INSTANCE_LABEL, IS_LOCAL_MODE } from '@/config'; import { Dashboard, useDashboards } from '@/dashboard'; import { useFavorites } from '@/favorites'; import { setHdxIdentity } from '@/hdxDebug'; @@ -366,6 +366,11 @@ export default function AppNav({ fixed = false }: { fixed?: boolean }) { ) : ( {wordmark} + {INSTANCE_LABEL && ( + + {INSTANCE_LABEL} + + )} {isUTC && ( Date: Wed, 30 Sep 2026 09:13:47 -0500 Subject: [PATCH 04/20] fix: address review findings on sidebar instance label Cap the label at 7 chars, not 9 - verified live that 8+ chars wraps the sidebar header and pushes the collapse button down when the UTC badge is also shown. Also swap the raw styled for Mantine's , per repo convention. Co-Authored-By: Claude Sonnet 5 --- .changeset/instance-label-brand-name.md | 2 +- packages/app/src/__tests__/config.instanceLabel.test.ts | 4 ++-- packages/app/src/components/AppNav/AppNav.tsx | 4 ++-- packages/app/src/config.ts | 5 +++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.changeset/instance-label-brand-name.md b/.changeset/instance-label-brand-name.md index 973b0d651f..378400af18 100644 --- a/.changeset/instance-label-brand-name.md +++ b/.changeset/instance-label-brand-name.md @@ -4,4 +4,4 @@ feat: add optional `NEXT_PUBLIC_INSTANCE_LABEL` suffix to the tab title and sidebar -Operators running multiple HyperDX instances (e.g. one per region) can now set `NEXT_PUBLIC_INSTANCE_LABEL` to append a short label (max 9 chars) to the browser tab title and sidebar wordmark, e.g. "HyperDX UK". Empty by default, no behavior change if unset. +Operators running multiple HyperDX instances (e.g. one per region) can now set `NEXT_PUBLIC_INSTANCE_LABEL` to append a short label (max 7 chars) to the browser tab title and sidebar wordmark, e.g. "HyperDX UK". Empty by default, no behavior change if unset. diff --git a/packages/app/src/__tests__/config.instanceLabel.test.ts b/packages/app/src/__tests__/config.instanceLabel.test.ts index 08836075ad..58d5566123 100644 --- a/packages/app/src/__tests__/config.instanceLabel.test.ts +++ b/packages/app/src/__tests__/config.instanceLabel.test.ts @@ -3,7 +3,7 @@ jest.mock('next-runtime-env', () => ({ env: () => ' ExtraLongLabel ' })); import { INSTANCE_LABEL } from '@/config'; describe('INSTANCE_LABEL', () => { - it('trims whitespace and caps at 9 characters', () => { - expect(INSTANCE_LABEL).toBe('ExtraLong'); + it('trims whitespace and caps at 7 characters', () => { + expect(INSTANCE_LABEL).toBe('ExtraLo'); }); }); diff --git a/packages/app/src/components/AppNav/AppNav.tsx b/packages/app/src/components/AppNav/AppNav.tsx index bcf329c233..e3bef93aed 100644 --- a/packages/app/src/components/AppNav/AppNav.tsx +++ b/packages/app/src/components/AppNav/AppNav.tsx @@ -367,9 +367,9 @@ export default function AppNav({ fixed = false }: { fixed?: boolean }) { {wordmark} {INSTANCE_LABEL && ( - + {INSTANCE_LABEL} - + )} {isUTC && ( Date: Wed, 30 Sep 2026 09:28:25 -0500 Subject: [PATCH 05/20] fix: prevent runaway title-observer loop, slice label by code point document.title strips trailing whitespace on read, so a label whose suffix ends in whitespace never matches endsWith - the observer kept re-appending it on every mutation it triggered, an unbounded loop that froze the tab (reproduced live). Discard our own write's mutation record via observer.takeRecords() instead of relying on that comparison. Also switch config.ts's slice to operate on code points, not UTF-16 units, so an emoji at the 7-char boundary isn't split into a broken glyph. Co-Authored-By: Claude Sonnet 5 --- .../config.instanceLabel.emoji.test.ts | 9 +++++++++ packages/app/src/config.ts | 8 +++++--- .../__tests__/useInstanceLabelTitle.test.tsx | 9 +++------ .../useInstanceLabelTitle.whitespace.test.tsx | 18 ++++++++++++++++++ .../app/src/hooks/useInstanceLabelTitle.ts | 10 +++++++--- 5 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 packages/app/src/__tests__/config.instanceLabel.emoji.test.ts create mode 100644 packages/app/src/hooks/__tests__/useInstanceLabelTitle.whitespace.test.tsx diff --git a/packages/app/src/__tests__/config.instanceLabel.emoji.test.ts b/packages/app/src/__tests__/config.instanceLabel.emoji.test.ts new file mode 100644 index 0000000000..6b62318809 --- /dev/null +++ b/packages/app/src/__tests__/config.instanceLabel.emoji.test.ts @@ -0,0 +1,9 @@ +jest.mock('next-runtime-env', () => ({ env: () => 'prod-U😀' })); + +import { INSTANCE_LABEL } from '@/config'; + +describe('INSTANCE_LABEL (emoji input)', () => { + it('slices by code point instead of splitting a surrogate pair', () => { + expect(INSTANCE_LABEL).toBe('prod-U😀'); + }); +}); diff --git a/packages/app/src/config.ts b/packages/app/src/config.ts index db56f9fe6f..bc72aa1296 100644 --- a/packages/app/src/config.ts +++ b/packages/app/src/config.ts @@ -84,9 +84,11 @@ export const IS_SESSIONS_ENABLED = true; export const IS_PROMQL_ENABLED = env('NEXT_PUBLIC_ENABLE_PROMQL') === 'true'; // Suffix for the tab title/sidebar wordmark; capped at 7 chars so it still // fits next to the sidebar's UTC badge without wrapping. -export const INSTANCE_LABEL = (env('NEXT_PUBLIC_INSTANCE_LABEL') ?? '') - .trim() - .slice(0, 7); +export const INSTANCE_LABEL = [ + ...(env('NEXT_PUBLIC_INSTANCE_LABEL') ?? '').trim(), +] + .slice(0, 7) + .join(''); // Alert detail page (/alerts/:id). Default off — currently enabled only in // dev (.env.development) and CI (e2e webserver) while the feature bakes. export const IS_ALERT_DETAILS_ENABLED = diff --git a/packages/app/src/hooks/__tests__/useInstanceLabelTitle.test.tsx b/packages/app/src/hooks/__tests__/useInstanceLabelTitle.test.tsx index c2da00a68e..df5baafcc3 100644 --- a/packages/app/src/hooks/__tests__/useInstanceLabelTitle.test.tsx +++ b/packages/app/src/hooks/__tests__/useInstanceLabelTitle.test.tsx @@ -14,14 +14,11 @@ describe('useInstanceLabelTitle', () => { expect(document.title).toBe('Search - HyperDX UK'); }); - it('keeps appending the label as the title changes on navigation', done => { + it('keeps appending the label as the title changes on navigation', async () => { renderHook(() => useInstanceLabelTitle()); document.title = 'Alerts - HyperDX'; - // MutationObserver callbacks are microtasks; flush before asserting. - queueMicrotask(() => { - expect(document.title).toBe('Alerts - HyperDX UK'); - done(); - }); + await new Promise(resolve => setTimeout(resolve, 0)); + expect(document.title).toBe('Alerts - HyperDX UK'); }); it('does not double-append if the title already has the suffix', () => { diff --git a/packages/app/src/hooks/__tests__/useInstanceLabelTitle.whitespace.test.tsx b/packages/app/src/hooks/__tests__/useInstanceLabelTitle.whitespace.test.tsx new file mode 100644 index 0000000000..13a216ba24 --- /dev/null +++ b/packages/app/src/hooks/__tests__/useInstanceLabelTitle.whitespace.test.tsx @@ -0,0 +1,18 @@ +import { renderHook } from '@testing-library/react'; + +jest.mock('@/config', () => ({ INSTANCE_LABEL: 'AB CDEF ' })); + +import { useInstanceLabelTitle } from '@/hooks/useInstanceLabelTitle'; + +describe('useInstanceLabelTitle (suffix ends in whitespace)', () => { + it('does not grow the title unboundedly', async () => { + document.title = 'Search - HyperDX'; + renderHook(() => useInstanceLabelTitle()); + await Promise.resolve(); + await Promise.resolve(); + const lengthAfterFirstFlush = document.title.length; + await Promise.resolve(); + await Promise.resolve(); + expect(document.title.length).toBe(lengthAfterFirstFlush); + }); +}); diff --git a/packages/app/src/hooks/useInstanceLabelTitle.ts b/packages/app/src/hooks/useInstanceLabelTitle.ts index 993d29643b..956a242df9 100644 --- a/packages/app/src/hooks/useInstanceLabelTitle.ts +++ b/packages/app/src/hooks/useInstanceLabelTitle.ts @@ -14,13 +14,17 @@ export function useInstanceLabelTitle(): void { if (!titleEl) { return; } + // document.title strips trailing whitespace, so discard our own write's + // mutation record rather than trusting endsWith to stop the loop. const applySuffix = () => { - if (!document.title.endsWith(suffix)) { - document.title = `${document.title}${suffix}`; + if (document.title.endsWith(suffix)) { + return; } + document.title = `${document.title}${suffix}`; + observer.takeRecords(); }; - applySuffix(); const observer = new MutationObserver(applySuffix); + applySuffix(); observer.observe(titleEl, { childList: true, characterData: true, From 281ce4e886e554b47607ffd9d3b5e24f1a085bb6 Mon Sep 17 00:00:00 2001 From: arj22 Date: Wed, 30 Sep 2026 12:57:36 -0500 Subject: [PATCH 06/20] fix: address deep-review P2s - debug snapshot and test coverage Add instanceLabel to hdxDebug's staticFeatures snapshot so bug reports show whether it's active. Extract the sidebar label into its own InstanceLabel component so it's testable without mounting all of AppNav's dependencies, and add tests for both the set and unset cases. Co-Authored-By: Claude Sonnet 5 --- packages/app/src/components/AppNav/AppNav.tsx | 9 +++------ .../app/src/components/AppNav/InstanceLabel.tsx | 14 ++++++++++++++ .../__tests__/InstanceLabel.no-label.test.tsx | 12 ++++++++++++ .../AppNav/__tests__/InstanceLabel.test.tsx | 17 +++++++++++++++++ packages/app/src/hdxDebug.ts | 2 ++ 5 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 packages/app/src/components/AppNav/InstanceLabel.tsx create mode 100644 packages/app/src/components/AppNav/__tests__/InstanceLabel.no-label.test.tsx create mode 100644 packages/app/src/components/AppNav/__tests__/InstanceLabel.test.tsx diff --git a/packages/app/src/components/AppNav/AppNav.tsx b/packages/app/src/components/AppNav/AppNav.tsx index e3bef93aed..e19ce7ce77 100644 --- a/packages/app/src/components/AppNav/AppNav.tsx +++ b/packages/app/src/components/AppNav/AppNav.tsx @@ -30,7 +30,8 @@ import { import api from '@/api'; import { AlertStatusIcon } from '@/components/AlertStatusIcon'; -import { APP_VERSION, INSTANCE_LABEL, IS_LOCAL_MODE } from '@/config'; +import { InstanceLabel } from '@/components/AppNav/InstanceLabel'; +import { APP_VERSION, IS_LOCAL_MODE } from '@/config'; import { Dashboard, useDashboards } from '@/dashboard'; import { useFavorites } from '@/favorites'; import { setHdxIdentity } from '@/hdxDebug'; @@ -366,11 +367,7 @@ export default function AppNav({ fixed = false }: { fixed?: boolean }) { ) : ( {wordmark} - {INSTANCE_LABEL && ( - - {INSTANCE_LABEL} - - )} + {isUTC && ( + {INSTANCE_LABEL} + + ); +} diff --git a/packages/app/src/components/AppNav/__tests__/InstanceLabel.no-label.test.tsx b/packages/app/src/components/AppNav/__tests__/InstanceLabel.no-label.test.tsx new file mode 100644 index 0000000000..54b7270e5d --- /dev/null +++ b/packages/app/src/components/AppNav/__tests__/InstanceLabel.no-label.test.tsx @@ -0,0 +1,12 @@ +import { render } from '@testing-library/react'; + +jest.mock('@/config', () => ({ INSTANCE_LABEL: '' })); + +import { InstanceLabel } from '@/components/AppNav/InstanceLabel'; + +describe('InstanceLabel (INSTANCE_LABEL unset)', () => { + it('renders nothing', () => { + const { container } = render(); + expect(container).toBeEmptyDOMElement(); + }); +}); diff --git a/packages/app/src/components/AppNav/__tests__/InstanceLabel.test.tsx b/packages/app/src/components/AppNav/__tests__/InstanceLabel.test.tsx new file mode 100644 index 0000000000..690fa5b342 --- /dev/null +++ b/packages/app/src/components/AppNav/__tests__/InstanceLabel.test.tsx @@ -0,0 +1,17 @@ +import { MantineProvider } from '@mantine/core'; +import { render, screen } from '@testing-library/react'; + +jest.mock('@/config', () => ({ INSTANCE_LABEL: 'UK' })); + +import { InstanceLabel } from '@/components/AppNav/InstanceLabel'; + +describe('InstanceLabel', () => { + it('renders the label when INSTANCE_LABEL is set', () => { + render( + + + , + ); + expect(screen.getByText('UK')).toBeInTheDocument(); + }); +}); diff --git a/packages/app/src/hdxDebug.ts b/packages/app/src/hdxDebug.ts index 5728aa8951..1f78812761 100644 --- a/packages/app/src/hdxDebug.ts +++ b/packages/app/src/hdxDebug.ts @@ -4,6 +4,7 @@ import HyperDX from '@hyperdx/browser'; import { APP_VERSION, BASE_PATH, + INSTANCE_LABEL, IS_ALERT_DETAILS_ENABLED, IS_CLICKHOUSE_BUILD, IS_DEV, @@ -84,6 +85,7 @@ const staticFeatures: Record = { promql: IS_PROMQL_ENABLED, llmCost: IS_LLM_COST_ENABLED, alertDetails: IS_ALERT_DETAILS_ENABLED, + instanceLabel: Boolean(INSTANCE_LABEL), }; // config.ts's IS_OSS has a precedence quirk (`?? 'true' === 'true'`), so a set From b6da722c485e3e187d8bd4f411cd83680097dc13 Mon Sep 17 00:00:00 2001 From: arj22 Date: Wed, 30 Sep 2026 13:48:58 -0500 Subject: [PATCH 07/20] docs: note the sidebar label only shows when expanded The 50px collapsed sidebar has no room for a text label. Documenting this instead of redesigning the collapsed state for it. Co-Authored-By: Claude Sonnet 5 --- .changeset/instance-label-brand-name.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/instance-label-brand-name.md b/.changeset/instance-label-brand-name.md index 378400af18..de08fa2b37 100644 --- a/.changeset/instance-label-brand-name.md +++ b/.changeset/instance-label-brand-name.md @@ -4,4 +4,4 @@ feat: add optional `NEXT_PUBLIC_INSTANCE_LABEL` suffix to the tab title and sidebar -Operators running multiple HyperDX instances (e.g. one per region) can now set `NEXT_PUBLIC_INSTANCE_LABEL` to append a short label (max 7 chars) to the browser tab title and sidebar wordmark, e.g. "HyperDX UK". Empty by default, no behavior change if unset. +Operators running multiple HyperDX instances (e.g. one per region) can now set `NEXT_PUBLIC_INSTANCE_LABEL` to append a short label (max 7 chars) to the browser tab title and sidebar wordmark, e.g. "HyperDX UK". Empty by default, no behavior change if unset. The sidebar label only shows when the sidebar is expanded. From e018165704e2d357103063a477f3b8e184ab68d8 Mon Sep 17 00:00:00 2001 From: arj22 Date: Mon, 5 Oct 2026 12:22:06 -0500 Subject: [PATCH 08/20] fix: address Brandon's review comments on instance label Simplify the title suffix into a hook that returns a string instead of only mutating the DOM, use it directly in _app.tsx's title JSX, style the sidebar label as a pill matching the UTC badge (mutually exclusive with it), fix truncation to stay on one row, and drop the 7-char cap now that the label only needs to fit visually, not everywhere. Co-Authored-By: Claude Sonnet 5 --- packages/app/pages/_app.tsx | 9 ++-- .../config.instanceLabel.emoji.test.ts | 4 +- .../__tests__/config.instanceLabel.test.ts | 4 +- .../src/components/AppNav/AppNav.module.scss | 2 + packages/app/src/components/AppNav/AppNav.tsx | 36 +++++++++------ .../src/components/AppNav/InstanceLabel.tsx | 15 +++++-- packages/app/src/config.ts | 11 ++--- .../useInstanceLabelTitle.no-label.test.tsx | 13 ------ .../useTitleSuffix.no-label.test.tsx | 18 ++++++++ ...Title.test.tsx => useTitleSuffix.test.tsx} | 17 ++++--- ...tsx => useTitleSuffix.whitespace.test.tsx} | 6 +-- .../app/src/hooks/useInstanceLabelTitle.ts | 35 --------------- packages/app/src/hooks/useTitleSuffix.ts | 45 +++++++++++++++++++ 13 files changed, 128 insertions(+), 87 deletions(-) delete mode 100644 packages/app/src/hooks/__tests__/useInstanceLabelTitle.no-label.test.tsx create mode 100644 packages/app/src/hooks/__tests__/useTitleSuffix.no-label.test.tsx rename packages/app/src/hooks/__tests__/{useInstanceLabelTitle.test.tsx => useTitleSuffix.test.tsx} (59%) rename packages/app/src/hooks/__tests__/{useInstanceLabelTitle.whitespace.test.tsx => useTitleSuffix.whitespace.test.tsx} (71%) delete mode 100644 packages/app/src/hooks/useInstanceLabelTitle.ts create mode 100644 packages/app/src/hooks/useTitleSuffix.ts diff --git a/packages/app/pages/_app.tsx b/packages/app/pages/_app.tsx index 331140b662..530a2bb9d1 100644 --- a/packages/app/pages/_app.tsx +++ b/packages/app/pages/_app.tsx @@ -23,7 +23,7 @@ import { } from '@/config/fonts'; import { ibmPlexMono, inter, roboto, robotoMono } from '@/fonts'; import { fetchServerVersion, installHdxDebug } from '@/hdxDebug'; -import { useInstanceLabelTitle } from '@/hooks/useInstanceLabelTitle'; +import { useTitleSuffix } from '@/hooks/useTitleSuffix'; import { AppThemeProvider, useAppTheme } from '@/theme/ThemeProvider'; import { ThemeWrapper } from '@/ThemeWrapper'; import { NextApiConfigResponseData } from '@/types'; @@ -72,11 +72,14 @@ type AppPropsWithLayout = AppProps & { // Must be rendered inside AppThemeProvider to avoid hydration mismatch function AppHeadContent() { const { theme } = useAppTheme(); - useInstanceLabelTitle(); + const suffix = useTitleSuffix(); return ( - {theme.displayName} + + {theme.displayName} + {suffix} + diff --git a/packages/app/src/__tests__/config.instanceLabel.emoji.test.ts b/packages/app/src/__tests__/config.instanceLabel.emoji.test.ts index 6b62318809..b04bde33c8 100644 --- a/packages/app/src/__tests__/config.instanceLabel.emoji.test.ts +++ b/packages/app/src/__tests__/config.instanceLabel.emoji.test.ts @@ -1,9 +1,9 @@ -jest.mock('next-runtime-env', () => ({ env: () => 'prod-U😀' })); +jest.mock('next-runtime-env', () => ({ env: () => ' prod-U😀 ' })); import { INSTANCE_LABEL } from '@/config'; describe('INSTANCE_LABEL (emoji input)', () => { - it('slices by code point instead of splitting a surrogate pair', () => { + it('trims without mangling multi-byte characters', () => { expect(INSTANCE_LABEL).toBe('prod-U😀'); }); }); diff --git a/packages/app/src/__tests__/config.instanceLabel.test.ts b/packages/app/src/__tests__/config.instanceLabel.test.ts index 58d5566123..830b491ec2 100644 --- a/packages/app/src/__tests__/config.instanceLabel.test.ts +++ b/packages/app/src/__tests__/config.instanceLabel.test.ts @@ -3,7 +3,7 @@ jest.mock('next-runtime-env', () => ({ env: () => ' ExtraLongLabel ' })); import { INSTANCE_LABEL } from '@/config'; describe('INSTANCE_LABEL', () => { - it('trims whitespace and caps at 7 characters', () => { - expect(INSTANCE_LABEL).toBe('ExtraLo'); + it('trims whitespace without capping length', () => { + expect(INSTANCE_LABEL).toBe('ExtraLongLabel'); }); }); diff --git a/packages/app/src/components/AppNav/AppNav.module.scss b/packages/app/src/components/AppNav/AppNav.module.scss index 9613ba65f9..45afbe6344 100644 --- a/packages/app/src/components/AppNav/AppNav.module.scss +++ b/packages/app/src/components/AppNav/AppNav.module.scss @@ -109,6 +109,8 @@ $transition-slow: 0.2s ease; align-items: center; justify-content: center; color: var(--color-text); + min-width: 0; + flex: 1; } .logoIconWrapper { diff --git a/packages/app/src/components/AppNav/AppNav.tsx b/packages/app/src/components/AppNav/AppNav.tsx index e19ce7ce77..3ae4e48b6e 100644 --- a/packages/app/src/components/AppNav/AppNav.tsx +++ b/packages/app/src/components/AppNav/AppNav.tsx @@ -31,7 +31,7 @@ import { import api from '@/api'; import { AlertStatusIcon } from '@/components/AlertStatusIcon'; import { InstanceLabel } from '@/components/AppNav/InstanceLabel'; -import { APP_VERSION, IS_LOCAL_MODE } from '@/config'; +import { APP_VERSION, INSTANCE_LABEL, IS_LOCAL_MODE } from '@/config'; import { Dashboard, useDashboards } from '@/dashboard'; import { useFavorites } from '@/favorites'; import { setHdxIdentity } from '@/hdxDebug'; @@ -365,19 +365,29 @@ export default function AppNav({ fixed = false }: { fixed?: boolean }) { {isCollapsed ? (
{logomark}
) : ( - + {wordmark} - - {isUTC && ( - - UTC - + {/* Label and UTC badge are mutually exclusive - showing both + would be redundant and crowd this already-tight row. */} + {INSTANCE_LABEL ? ( + + ) : ( + isUTC && ( + + UTC + + ) )} )} diff --git a/packages/app/src/components/AppNav/InstanceLabel.tsx b/packages/app/src/components/AppNav/InstanceLabel.tsx index f2dd24f5de..d16a0df03b 100644 --- a/packages/app/src/components/AppNav/InstanceLabel.tsx +++ b/packages/app/src/components/AppNav/InstanceLabel.tsx @@ -1,14 +1,23 @@ -import { Text } from '@mantine/core'; +import { Badge } from '@mantine/core'; import { INSTANCE_LABEL } from '@/config'; +// Styled to match the sidebar's UTC badge; see AppNav.tsx, where the two are +// mutually exclusive (the label takes priority when set). export function InstanceLabel() { if (!INSTANCE_LABEL) { return null; } return ( - + {INSTANCE_LABEL} - +
); } diff --git a/packages/app/src/config.ts b/packages/app/src/config.ts index bc72aa1296..3597e4fa34 100644 --- a/packages/app/src/config.ts +++ b/packages/app/src/config.ts @@ -82,13 +82,10 @@ export const IS_METRICS_ENABLED = true; export const IS_MTVIEWS_ENABLED = false; export const IS_SESSIONS_ENABLED = true; export const IS_PROMQL_ENABLED = env('NEXT_PUBLIC_ENABLE_PROMQL') === 'true'; -// Suffix for the tab title/sidebar wordmark; capped at 7 chars so it still -// fits next to the sidebar's UTC badge without wrapping. -export const INSTANCE_LABEL = [ - ...(env('NEXT_PUBLIC_INSTANCE_LABEL') ?? '').trim(), -] - .slice(0, 7) - .join(''); +// Suffix for the tab title/sidebar pill. Shown in full in the page title; +// only truncated visually (via CSS ellipsis) in the sidebar, where space is +// constrained. +export const INSTANCE_LABEL = (env('NEXT_PUBLIC_INSTANCE_LABEL') ?? '').trim(); // Alert detail page (/alerts/:id). Default off — currently enabled only in // dev (.env.development) and CI (e2e webserver) while the feature bakes. export const IS_ALERT_DETAILS_ENABLED = diff --git a/packages/app/src/hooks/__tests__/useInstanceLabelTitle.no-label.test.tsx b/packages/app/src/hooks/__tests__/useInstanceLabelTitle.no-label.test.tsx deleted file mode 100644 index d9deea73c8..0000000000 --- a/packages/app/src/hooks/__tests__/useInstanceLabelTitle.no-label.test.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { renderHook } from '@testing-library/react'; - -jest.mock('@/config', () => ({ INSTANCE_LABEL: '' })); - -import { useInstanceLabelTitle } from '@/hooks/useInstanceLabelTitle'; - -describe('useInstanceLabelTitle (INSTANCE_LABEL unset)', () => { - it('leaves the title untouched', () => { - document.title = 'Search - HyperDX'; - renderHook(() => useInstanceLabelTitle()); - expect(document.title).toBe('Search - HyperDX'); - }); -}); diff --git a/packages/app/src/hooks/__tests__/useTitleSuffix.no-label.test.tsx b/packages/app/src/hooks/__tests__/useTitleSuffix.no-label.test.tsx new file mode 100644 index 0000000000..2a1f570020 --- /dev/null +++ b/packages/app/src/hooks/__tests__/useTitleSuffix.no-label.test.tsx @@ -0,0 +1,18 @@ +import { renderHook } from '@testing-library/react'; + +jest.mock('@/config', () => ({ INSTANCE_LABEL: '' })); + +import { useTitleSuffix } from '@/hooks/useTitleSuffix'; + +describe('useTitleSuffix (INSTANCE_LABEL unset)', () => { + it('returns an empty suffix', () => { + const { result } = renderHook(() => useTitleSuffix()); + expect(result.current).toBe(''); + }); + + it('leaves the title untouched', () => { + document.title = 'Search - HyperDX'; + renderHook(() => useTitleSuffix()); + expect(document.title).toBe('Search - HyperDX'); + }); +}); diff --git a/packages/app/src/hooks/__tests__/useInstanceLabelTitle.test.tsx b/packages/app/src/hooks/__tests__/useTitleSuffix.test.tsx similarity index 59% rename from packages/app/src/hooks/__tests__/useInstanceLabelTitle.test.tsx rename to packages/app/src/hooks/__tests__/useTitleSuffix.test.tsx index df5baafcc3..d16a209455 100644 --- a/packages/app/src/hooks/__tests__/useInstanceLabelTitle.test.tsx +++ b/packages/app/src/hooks/__tests__/useTitleSuffix.test.tsx @@ -2,20 +2,25 @@ import { renderHook } from '@testing-library/react'; jest.mock('@/config', () => ({ INSTANCE_LABEL: 'UK' })); -import { useInstanceLabelTitle } from '@/hooks/useInstanceLabelTitle'; +import { useTitleSuffix } from '@/hooks/useTitleSuffix'; -describe('useInstanceLabelTitle', () => { +describe('useTitleSuffix', () => { beforeEach(() => { document.title = 'Search - HyperDX'; }); - it('appends the instance label to the current title', () => { - renderHook(() => useInstanceLabelTitle()); + it('returns the suffix for call sites that render their own title', () => { + const { result } = renderHook(() => useTitleSuffix()); + expect(result.current).toBe(' UK'); + }); + + it('also appends the instance label to the current title', () => { + renderHook(() => useTitleSuffix()); expect(document.title).toBe('Search - HyperDX UK'); }); it('keeps appending the label as the title changes on navigation', async () => { - renderHook(() => useInstanceLabelTitle()); + renderHook(() => useTitleSuffix()); document.title = 'Alerts - HyperDX'; await new Promise(resolve => setTimeout(resolve, 0)); expect(document.title).toBe('Alerts - HyperDX UK'); @@ -23,7 +28,7 @@ describe('useInstanceLabelTitle', () => { it('does not double-append if the title already has the suffix', () => { document.title = 'Search - HyperDX UK'; - renderHook(() => useInstanceLabelTitle()); + renderHook(() => useTitleSuffix()); expect(document.title).toBe('Search - HyperDX UK'); }); }); diff --git a/packages/app/src/hooks/__tests__/useInstanceLabelTitle.whitespace.test.tsx b/packages/app/src/hooks/__tests__/useTitleSuffix.whitespace.test.tsx similarity index 71% rename from packages/app/src/hooks/__tests__/useInstanceLabelTitle.whitespace.test.tsx rename to packages/app/src/hooks/__tests__/useTitleSuffix.whitespace.test.tsx index 13a216ba24..c2fc28957a 100644 --- a/packages/app/src/hooks/__tests__/useInstanceLabelTitle.whitespace.test.tsx +++ b/packages/app/src/hooks/__tests__/useTitleSuffix.whitespace.test.tsx @@ -2,12 +2,12 @@ import { renderHook } from '@testing-library/react'; jest.mock('@/config', () => ({ INSTANCE_LABEL: 'AB CDEF ' })); -import { useInstanceLabelTitle } from '@/hooks/useInstanceLabelTitle'; +import { useTitleSuffix } from '@/hooks/useTitleSuffix'; -describe('useInstanceLabelTitle (suffix ends in whitespace)', () => { +describe('useTitleSuffix (suffix ends in whitespace)', () => { it('does not grow the title unboundedly', async () => { document.title = 'Search - HyperDX'; - renderHook(() => useInstanceLabelTitle()); + renderHook(() => useTitleSuffix()); await Promise.resolve(); await Promise.resolve(); const lengthAfterFirstFlush = document.title.length; diff --git a/packages/app/src/hooks/useInstanceLabelTitle.ts b/packages/app/src/hooks/useInstanceLabelTitle.ts deleted file mode 100644 index 956a242df9..0000000000 --- a/packages/app/src/hooks/useInstanceLabelTitle.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { useEffect } from 'react'; - -import { INSTANCE_LABEL } from '@/config'; - -/** Appends INSTANCE_LABEL to the tab title via a MutationObserver, so every - * page gets it without each one needing its own change. */ -export function useInstanceLabelTitle(): void { - useEffect(() => { - if (!INSTANCE_LABEL) { - return; - } - const suffix = ` ${INSTANCE_LABEL}`; - const titleEl = document.querySelector('title'); - if (!titleEl) { - return; - } - // document.title strips trailing whitespace, so discard our own write's - // mutation record rather than trusting endsWith to stop the loop. - const applySuffix = () => { - if (document.title.endsWith(suffix)) { - return; - } - document.title = `${document.title}${suffix}`; - observer.takeRecords(); - }; - const observer = new MutationObserver(applySuffix); - applySuffix(); - observer.observe(titleEl, { - childList: true, - characterData: true, - subtree: true, - }); - return () => observer.disconnect(); - }, []); -} diff --git a/packages/app/src/hooks/useTitleSuffix.ts b/packages/app/src/hooks/useTitleSuffix.ts new file mode 100644 index 0000000000..b9a3c95641 --- /dev/null +++ b/packages/app/src/hooks/useTitleSuffix.ts @@ -0,0 +1,45 @@ +import { useEffect } from 'react'; + +import { INSTANCE_LABEL } from '@/config'; + +const SUFFIX = INSTANCE_LABEL ? ` ${INSTANCE_LABEL}` : ''; + +/** + * Returns the instance-label suffix to append to a page title (empty string + * when unset) for call sites that render their own ``. + * + * Also keeps the browser tab's title suffixed as a side effect, for the many + * existing pages that render their own `<title>X - {brandName}` and + * so override whatever `_app.tsx` renders — a MutationObserver is the only + * way to reach those without threading the suffix through every page. + */ +export function useTitleSuffix(): string { + useEffect(() => { + if (!SUFFIX) { + return; + } + const titleEl = document.querySelector('title'); + if (!titleEl) { + return; + } + // document.title strips trailing whitespace, so discard our own write's + // mutation record rather than trusting endsWith to stop the loop. + const applySuffix = () => { + if (document.title.endsWith(SUFFIX)) { + return; + } + document.title = `${document.title}${SUFFIX}`; + observer.takeRecords(); + }; + const observer = new MutationObserver(applySuffix); + applySuffix(); + observer.observe(titleEl, { + childList: true, + characterData: true, + subtree: true, + }); + return () => observer.disconnect(); + }, []); + + return SUFFIX; +} From 8a6959fc4506d62d46fbb9d8badf9ad546d014f8 Mon Sep 17 00:00:00 2001 From: arj22 Date: Mon, 5 Oct 2026 12:59:11 -0500 Subject: [PATCH 09/20] docs: fix stale 7-char claim in changeset, note UTC replacement Co-Authored-By: Claude Sonnet 5 --- .changeset/instance-label-brand-name.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/instance-label-brand-name.md b/.changeset/instance-label-brand-name.md index de08fa2b37..19c3ac011d 100644 --- a/.changeset/instance-label-brand-name.md +++ b/.changeset/instance-label-brand-name.md @@ -4,4 +4,4 @@ feat: add optional `NEXT_PUBLIC_INSTANCE_LABEL` suffix to the tab title and sidebar -Operators running multiple HyperDX instances (e.g. one per region) can now set `NEXT_PUBLIC_INSTANCE_LABEL` to append a short label (max 7 chars) to the browser tab title and sidebar wordmark, e.g. "HyperDX UK". Empty by default, no behavior change if unset. The sidebar label only shows when the sidebar is expanded. +Operators running multiple HyperDX instances (e.g. one per region) can now set `NEXT_PUBLIC_INSTANCE_LABEL` to append a short label to the browser tab title and sidebar, e.g. "HyperDX UK". Empty by default, no behavior change if unset. The sidebar label only shows when the sidebar is expanded, and replaces the UTC badge there when both are set. From d9fbfc4a777fb426013e8a8ef0c4012a04d66e9e Mon Sep 17 00:00:00 2001 From: arj22 Date: Mon, 5 Oct 2026 13:35:40 -0500 Subject: [PATCH 10/20] fix: address claude-code-review and deep-review findings Collapse internal whitespace runs in INSTANCE_LABEL (both at the source and defensively in useTitleSuffix) so the tab-title dedup check can't mismatch against what document.title actually stores. Have InstanceLabel own its one guard via a fallback prop instead of AppNav checking INSTANCE_LABEL a second time, add tt="none" so the sidebar pill doesn't uppercase while the title keeps original case, and add test coverage for the fallback contract, the whitespace fix, and observer cleanup on unmount. Co-Authored-By: Claude Sonnet 5 --- .../config.instanceLabel.whitespace.test.ts | 9 ++++++ packages/app/src/components/AppNav/AppNav.tsx | 32 +++++++++---------- .../src/components/AppNav/InstanceLabel.tsx | 11 ++++--- .../__tests__/InstanceLabel.no-label.test.tsx | 9 ++++-- .../AppNav/__tests__/InstanceLabel.test.tsx | 10 ++++++ packages/app/src/config.ts | 8 +++-- .../hooks/__tests__/useTitleSuffix.test.tsx | 8 +++++ .../useTitleSuffix.whitespace.test.tsx | 24 ++++++++------ packages/app/src/hooks/useTitleSuffix.ts | 10 ++++-- 9 files changed, 85 insertions(+), 36 deletions(-) create mode 100644 packages/app/src/__tests__/config.instanceLabel.whitespace.test.ts diff --git a/packages/app/src/__tests__/config.instanceLabel.whitespace.test.ts b/packages/app/src/__tests__/config.instanceLabel.whitespace.test.ts new file mode 100644 index 0000000000..6ee10cbe30 --- /dev/null +++ b/packages/app/src/__tests__/config.instanceLabel.whitespace.test.ts @@ -0,0 +1,9 @@ +jest.mock('next-runtime-env', () => ({ env: () => 'EU West' })); + +import { INSTANCE_LABEL } from '@/config'; + +describe('INSTANCE_LABEL (internal whitespace run)', () => { + it('collapses internal whitespace to a single space', () => { + expect(INSTANCE_LABEL).toBe('EU West'); + }); +}); diff --git a/packages/app/src/components/AppNav/AppNav.tsx b/packages/app/src/components/AppNav/AppNav.tsx index 3ae4e48b6e..36e1bd9e2f 100644 --- a/packages/app/src/components/AppNav/AppNav.tsx +++ b/packages/app/src/components/AppNav/AppNav.tsx @@ -31,7 +31,7 @@ import { import api from '@/api'; import { AlertStatusIcon } from '@/components/AlertStatusIcon'; import { InstanceLabel } from '@/components/AppNav/InstanceLabel'; -import { APP_VERSION, INSTANCE_LABEL, IS_LOCAL_MODE } from '@/config'; +import { APP_VERSION, IS_LOCAL_MODE } from '@/config'; import { Dashboard, useDashboards } from '@/dashboard'; import { useFavorites } from '@/favorites'; import { setHdxIdentity } from '@/hdxDebug'; @@ -374,21 +374,21 @@ export default function AppNav({ fixed = false }: { fixed?: boolean }) { {wordmark} {/* Label and UTC badge are mutually exclusive - showing both would be redundant and crowd this already-tight row. */} - {INSTANCE_LABEL ? ( - - ) : ( - isUTC && ( - - UTC - - ) - )} + + UTC +
+ ) + } + />
)} diff --git a/packages/app/src/components/AppNav/InstanceLabel.tsx b/packages/app/src/components/AppNav/InstanceLabel.tsx index d16a0df03b..dd71c5bcb9 100644 --- a/packages/app/src/components/AppNav/InstanceLabel.tsx +++ b/packages/app/src/components/AppNav/InstanceLabel.tsx @@ -1,12 +1,14 @@ +import { ReactNode } from 'react'; import { Badge } from '@mantine/core'; import { INSTANCE_LABEL } from '@/config'; -// Styled to match the sidebar's UTC badge; see AppNav.tsx, where the two are -// mutually exclusive (the label takes priority when set). -export function InstanceLabel() { +// Styled to match the sidebar's UTC badge. `fallback` lets AppNav render the +// UTC badge in the same slot without needing its own INSTANCE_LABEL check - +// this component owns the one guard for whether a label is configured. +export function InstanceLabel({ fallback = null }: { fallback?: ReactNode }) { if (!INSTANCE_LABEL) { - return null; + return fallback; } return ( diff --git a/packages/app/src/components/AppNav/__tests__/InstanceLabel.no-label.test.tsx b/packages/app/src/components/AppNav/__tests__/InstanceLabel.no-label.test.tsx index 54b7270e5d..f3176b51ce 100644 --- a/packages/app/src/components/AppNav/__tests__/InstanceLabel.no-label.test.tsx +++ b/packages/app/src/components/AppNav/__tests__/InstanceLabel.no-label.test.tsx @@ -1,12 +1,17 @@ -import { render } from '@testing-library/react'; +import { render, screen } from '@testing-library/react'; jest.mock('@/config', () => ({ INSTANCE_LABEL: '' })); import { InstanceLabel } from '@/components/AppNav/InstanceLabel'; describe('InstanceLabel (INSTANCE_LABEL unset)', () => { - it('renders nothing', () => { + it('renders nothing by default', () => { const { container } = render(); expect(container).toBeEmptyDOMElement(); }); + + it('renders the fallback instead, e.g. the sidebar UTC badge', () => { + render(UTC} />); + expect(screen.getByText('UTC')).toBeInTheDocument(); + }); }); diff --git a/packages/app/src/components/AppNav/__tests__/InstanceLabel.test.tsx b/packages/app/src/components/AppNav/__tests__/InstanceLabel.test.tsx index 690fa5b342..0313e526f2 100644 --- a/packages/app/src/components/AppNav/__tests__/InstanceLabel.test.tsx +++ b/packages/app/src/components/AppNav/__tests__/InstanceLabel.test.tsx @@ -14,4 +14,14 @@ describe('InstanceLabel', () => { ); expect(screen.getByText('UK')).toBeInTheDocument(); }); + + it('ignores the fallback when a label is set, so they stay mutually exclusive', () => { + render( + + UTC} /> + , + ); + expect(screen.getByText('UK')).toBeInTheDocument(); + expect(screen.queryByText('UTC')).not.toBeInTheDocument(); + }); }); diff --git a/packages/app/src/config.ts b/packages/app/src/config.ts index 3597e4fa34..88f142b312 100644 --- a/packages/app/src/config.ts +++ b/packages/app/src/config.ts @@ -84,8 +84,12 @@ export const IS_SESSIONS_ENABLED = true; export const IS_PROMQL_ENABLED = env('NEXT_PUBLIC_ENABLE_PROMQL') === 'true'; // Suffix for the tab title/sidebar pill. Shown in full in the page title; // only truncated visually (via CSS ellipsis) in the sidebar, where space is -// constrained. -export const INSTANCE_LABEL = (env('NEXT_PUBLIC_INSTANCE_LABEL') ?? '').trim(); +// constrained. Internal whitespace is collapsed so it displays consistently +// and so the tab-title suffix (which compares against document.title, where +// the browser collapses whitespace runs) can reliably detect its own suffix. +export const INSTANCE_LABEL = (env('NEXT_PUBLIC_INSTANCE_LABEL') ?? '') + .trim() + .replace(/\s+/g, ' '); // Alert detail page (/alerts/:id). Default off — currently enabled only in // dev (.env.development) and CI (e2e webserver) while the feature bakes. export const IS_ALERT_DETAILS_ENABLED = diff --git a/packages/app/src/hooks/__tests__/useTitleSuffix.test.tsx b/packages/app/src/hooks/__tests__/useTitleSuffix.test.tsx index d16a209455..5dc3b302dc 100644 --- a/packages/app/src/hooks/__tests__/useTitleSuffix.test.tsx +++ b/packages/app/src/hooks/__tests__/useTitleSuffix.test.tsx @@ -31,4 +31,12 @@ describe('useTitleSuffix', () => { renderHook(() => useTitleSuffix()); expect(document.title).toBe('Search - HyperDX UK'); }); + + it('stops observing after unmount', async () => { + const { unmount } = renderHook(() => useTitleSuffix()); + unmount(); + document.title = 'Alerts - HyperDX'; + await new Promise(resolve => setTimeout(resolve, 0)); + expect(document.title).toBe('Alerts - HyperDX'); + }); }); diff --git a/packages/app/src/hooks/__tests__/useTitleSuffix.whitespace.test.tsx b/packages/app/src/hooks/__tests__/useTitleSuffix.whitespace.test.tsx index c2fc28957a..42484a91e2 100644 --- a/packages/app/src/hooks/__tests__/useTitleSuffix.whitespace.test.tsx +++ b/packages/app/src/hooks/__tests__/useTitleSuffix.whitespace.test.tsx @@ -1,18 +1,24 @@ import { renderHook } from '@testing-library/react'; -jest.mock('@/config', () => ({ INSTANCE_LABEL: 'AB CDEF ' })); +// A double space is a value real config.ts can produce before its own +// collapsing, and is also what document.title would collapse on write - +// this is the case that actually breaks the endsWith-based dedup check, +// not a trailing space (which .trim() already handles upstream). +jest.mock('@/config', () => ({ INSTANCE_LABEL: 'EU West' })); import { useTitleSuffix } from '@/hooks/useTitleSuffix'; -describe('useTitleSuffix (suffix ends in whitespace)', () => { - it('does not grow the title unboundedly', async () => { +describe('useTitleSuffix (label contains an internal whitespace run)', () => { + it('collapses the run so the suffix matches what document.title will store', () => { document.title = 'Search - HyperDX'; + const { result } = renderHook(() => useTitleSuffix()); + expect(result.current).toBe(' EU West'); + expect(document.title).toBe('Search - HyperDX EU West'); + }); + + it('does not double-append when the title already has the collapsed suffix', () => { + document.title = 'Search - HyperDX EU West'; renderHook(() => useTitleSuffix()); - await Promise.resolve(); - await Promise.resolve(); - const lengthAfterFirstFlush = document.title.length; - await Promise.resolve(); - await Promise.resolve(); - expect(document.title.length).toBe(lengthAfterFirstFlush); + expect(document.title).toBe('Search - HyperDX EU West'); }); }); diff --git a/packages/app/src/hooks/useTitleSuffix.ts b/packages/app/src/hooks/useTitleSuffix.ts index b9a3c95641..a72a93a2fb 100644 --- a/packages/app/src/hooks/useTitleSuffix.ts +++ b/packages/app/src/hooks/useTitleSuffix.ts @@ -2,11 +2,15 @@ import { useEffect } from 'react'; import { INSTANCE_LABEL } from '@/config'; -const SUFFIX = INSTANCE_LABEL ? ` ${INSTANCE_LABEL}` : ''; +// Collapsed defensively (not just relying on config.ts) since document.title +// collapses whitespace runs on write, and the dedup check below needs its +// comparison string to match what the browser will actually store. +const LABEL = INSTANCE_LABEL.replace(/\s+/g, ' '); +const SUFFIX = LABEL ? ` ${LABEL}` : ''; /** - * Returns the instance-label suffix to append to a page title (empty string - * when unset) for call sites that render their own ``. + * Returns the instance-label suffix to append to `_app.tsx`'s own base + * `<title>` (empty string when unset). * * Also keeps the browser tab's title suffixed as a side effect, for the many * existing pages that render their own `<title>X - {brandName}` and From 7343e1e1667e8ab9cbae1a1ea9a485af862b7c7c Mon Sep 17 00:00:00 2001 From: arj22 Date: Mon, 5 Oct 2026 14:51:53 -0500 Subject: [PATCH 11/20] fix: title SSR regression from array children {a}{b} passes React a two-element children array; its server renderer only writes a title for a single string/number child, so the SSR'd title came out empty until client hydration filled it in. Use one template-literal string instead. Co-Authored-By: Claude Sonnet 5 --- packages/app/pages/_app.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/app/pages/_app.tsx b/packages/app/pages/_app.tsx index 530a2bb9d1..7f2d6f2fb6 100644 --- a/packages/app/pages/_app.tsx +++ b/packages/app/pages/_app.tsx @@ -76,10 +76,7 @@ function AppHeadContent() { return ( - - {theme.displayName} - {suffix} - + {`${theme.displayName}${suffix}`} From 02dd79d2f263c32d40fe0d106971a8e53ab983cc Mon Sep 17 00:00:00 2001 From: arj22 Date: Mon, 5 Oct 2026 19:28:29 -0500 Subject: [PATCH 12/20] refactor: remove title-suffix MutationObserver, set titles directly Every page that renders its own now composes the instance label into it directly via getTitleSuffix(), instead of relying on a MutationObserver to patch it in after the fact. Renamed the suffix provider from useTitleSuffix to getTitleSuffix since it's a plain function now, not a hook - it was flagged by eslint-react's no-unnecessary-use-prefix rule once the useEffect was gone. Also fixes a pre-existing SSR title bug on the 3 pages with dynamic titles (DBDashboardPage, DBSearchPage, AlertDetailPage): their <title> had multiple JSX expression children, which React's server renderer doesn't collapse into a single string the way the client does - same class of bug just fixed on _app.tsx's own title in the base PR. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --- .changeset/instance-label-no-observer.md | 7 +++ packages/app/pages/_app.tsx | 4 +- packages/app/src/AlertDetailPage.tsx | 6 +-- packages/app/src/AlertsPage.tsx | 4 +- packages/app/src/CareersPage.tsx | 5 +- packages/app/src/ClickhousePage.tsx | 4 +- packages/app/src/DBChartPage.tsx | 4 +- packages/app/src/DBDashboardImportPage.tsx | 5 +- packages/app/src/DBDashboardPage.tsx | 6 +-- packages/app/src/DBSearchPage.tsx | 6 +-- packages/app/src/DBServiceMapPage.tsx | 6 ++- packages/app/src/KubernetesDashboardPage.tsx | 4 +- .../ServicesDashboardPage.tsx | 4 +- packages/app/src/SessionsPage.tsx | 4 +- packages/app/src/TeamPage.tsx | 5 +- .../Dashboards/DashboardTemplatesPage.tsx | 4 +- .../Dashboards/DashboardsListPage.tsx | 4 +- .../SavedSearches/SavedSearchesListPage.tsx | 4 +- .../getTitleSuffix.no-label.test.tsx | 12 +++++ .../hooks/__tests__/getTitleSuffix.test.tsx | 12 +++++ .../getTitleSuffix.whitespace.test.tsx | 12 +++++ .../useTitleSuffix.no-label.test.tsx | 18 ------- .../hooks/__tests__/useTitleSuffix.test.tsx | 42 ---------------- .../useTitleSuffix.whitespace.test.tsx | 24 --------- packages/app/src/hooks/getTitleSuffix.ts | 17 +++++++ packages/app/src/hooks/useTitleSuffix.ts | 49 ------------------- .../src/llm/dashboard/LLMDashboardPage.tsx | 4 +- 27 files changed, 117 insertions(+), 159 deletions(-) create mode 100644 .changeset/instance-label-no-observer.md create mode 100644 packages/app/src/hooks/__tests__/getTitleSuffix.no-label.test.tsx create mode 100644 packages/app/src/hooks/__tests__/getTitleSuffix.test.tsx create mode 100644 packages/app/src/hooks/__tests__/getTitleSuffix.whitespace.test.tsx delete mode 100644 packages/app/src/hooks/__tests__/useTitleSuffix.no-label.test.tsx delete mode 100644 packages/app/src/hooks/__tests__/useTitleSuffix.test.tsx delete mode 100644 packages/app/src/hooks/__tests__/useTitleSuffix.whitespace.test.tsx create mode 100644 packages/app/src/hooks/getTitleSuffix.ts delete mode 100644 packages/app/src/hooks/useTitleSuffix.ts diff --git a/.changeset/instance-label-no-observer.md b/.changeset/instance-label-no-observer.md new file mode 100644 index 0000000000..bfffe39320 --- /dev/null +++ b/.changeset/instance-label-no-observer.md @@ -0,0 +1,7 @@ +--- +'@hyperdx/app': patch +--- + +refactor: drop the instance-label MutationObserver, set the title directly on every page instead + +Every page that renders its own `<title>` now composes the instance-label suffix into it directly via `getTitleSuffix()`, removing the DOM-watching side effect that previously patched titles in after the fact. diff --git a/packages/app/pages/_app.tsx b/packages/app/pages/_app.tsx index 7f2d6f2fb6..eb46c87765 100644 --- a/packages/app/pages/_app.tsx +++ b/packages/app/pages/_app.tsx @@ -23,7 +23,7 @@ import { } from '@/config/fonts'; import { ibmPlexMono, inter, roboto, robotoMono } from '@/fonts'; import { fetchServerVersion, installHdxDebug } from '@/hdxDebug'; -import { useTitleSuffix } from '@/hooks/useTitleSuffix'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { AppThemeProvider, useAppTheme } from '@/theme/ThemeProvider'; import { ThemeWrapper } from '@/ThemeWrapper'; import { NextApiConfigResponseData } from '@/types'; @@ -72,7 +72,7 @@ type AppPropsWithLayout = AppProps & { // Must be rendered inside AppThemeProvider to avoid hydration mismatch function AppHeadContent() { const { theme } = useAppTheme(); - const suffix = useTitleSuffix(); + const suffix = getTitleSuffix(); return ( <Head> diff --git a/packages/app/src/AlertDetailPage.tsx b/packages/app/src/AlertDetailPage.tsx index ba69412ce4..86a3f9a5dd 100644 --- a/packages/app/src/AlertDetailPage.tsx +++ b/packages/app/src/AlertDetailPage.tsx @@ -28,6 +28,7 @@ import EmptyState from '@/components/EmptyState'; import { PageHeader } from '@/components/PageHeader'; import { TimePicker } from '@/components/TimePicker'; import { IS_ALERT_DETAILS_ENABLED } from '@/config'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { getAlertSourceLabel, getAlertSourceUrl } from '@/utils/alerts'; import { useBrandDisplayName } from './theme/ThemeProvider'; @@ -224,6 +225,7 @@ function AlertDetailBody({ alert }: { alert: AlertsPageItem }) { export default function AlertDetailPage() { const brandName = useBrandDisplayName(); + const suffix = getTitleSuffix(); const router = useRouter(); const alertId = typeof router.query.alertId === 'string' ? router.query.alertId : undefined; @@ -249,9 +251,7 @@ export default function AlertDetailPage() { style={{ display: 'flex', flexDirection: 'column', height: '100%' }} > <Head> - <title> - {alert ? `${alert.displayName} - Alerts` : 'Alerts'} - {brandName} - + {`${alert ? `${alert.displayName} - Alerts` : 'Alerts'} - ${brandName}${suffix}`} {isLoading && ( diff --git a/packages/app/src/AlertsPage.tsx b/packages/app/src/AlertsPage.tsx index 2ff9b8beb3..f58e3df1af 100644 --- a/packages/app/src/AlertsPage.tsx +++ b/packages/app/src/AlertsPage.tsx @@ -19,6 +19,7 @@ import { AlertCardList } from '@/components/alerts/AlertCardList'; import { AlertsFilterBar } from '@/components/alerts/AlertsFilterBar'; import EmptyState from '@/components/EmptyState'; import { PageHeader } from '@/components/PageHeader'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { ALERT_STATE_FILTER_OPTIONS } from '@/utils/alerts'; import { useBrandDisplayName } from './theme/ThemeProvider'; @@ -29,6 +30,7 @@ const SEARCH_DEBOUNCE_MS = 300; export default function AlertsPage() { const brandName = useBrandDisplayName(); + const suffix = getTitleSuffix(); const mounted = useMounted(); const [search, setSearch] = useQueryState('search'); @@ -114,7 +116,7 @@ export default function AlertsPage() { style={{ display: 'flex', flexDirection: 'column', minHeight: '100%' }} > - Alerts - {brandName} + {`Alerts - ${brandName}${suffix}`}
- Careers | HyperDX + {`Careers | HyperDX${suffix}`} diff --git a/packages/app/src/ClickhousePage.tsx b/packages/app/src/ClickhousePage.tsx index cb6de4a6f0..5c2fb93676 100644 --- a/packages/app/src/ClickhousePage.tsx +++ b/packages/app/src/ClickhousePage.tsx @@ -36,6 +36,7 @@ import { ConnectionSelectControlled } from '@/components/ConnectionSelect'; import { DBTimeChart } from '@/components/DBTimeChart'; import { PageLayout } from '@/components/PageLayout'; import { TimePicker } from '@/components/TimePicker'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { withAppNav } from '@/layout'; import { ChartCard } from './components/charts/ChartCard'; @@ -492,6 +493,7 @@ const DEFAULT_INTERVAL = 'Past 1h'; function ClickhousePage() { const defaultTimeRange = useDefaultTimeRange(DEFAULT_INTERVAL); const brandName = useBrandDisplayName(); + const suffix = getTitleSuffix(); const { colorScheme } = useMantineColorScheme(); const { data: connections } = useConnections(); const [_connection, setConnection] = useQueryState('connection'); @@ -644,7 +646,7 @@ function ClickhousePage() { content={ <> <Head> - <title>ClickHouse Dashboard – {brandName} + {`ClickHouse Dashboard – ${brandName}${suffix}`} - Chart Explorer - {brandName} + {`Chart Explorer - ${brandName}${suffix}`} - Import Dashboard - {brandName} + {`Import Dashboard - ${brandName}${suffix}`} diff --git a/packages/app/src/DBDashboardPage.tsx b/packages/app/src/DBDashboardPage.tsx index 7120338d20..3c0ff89475 100644 --- a/packages/app/src/DBDashboardPage.tsx +++ b/packages/app/src/DBDashboardPage.tsx @@ -159,6 +159,7 @@ import { useDashboards, useDeleteDashboard, } from '@/dashboard'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { useAlertAnnotations } from '@/hooks/useAlertAnnotations'; import useDashboardContainers, { TabDeleteAction, @@ -1883,6 +1884,7 @@ function DBDashboardPage({ isSetting: isSavingDashboard, } = dashboardProps; const brandName = useBrandDisplayName(); + const suffix = getTitleSuffix(); const confirm = useConfirm(); const { userPreferences: { isUTC }, @@ -3213,9 +3215,7 @@ function DBDashboardPage({ const dashboardBody = ( <> - - {dashboard?.name ? `${dashboard.name}` : 'Dashboard'} – {brandName} - + {`${dashboard?.name ? dashboard.name : 'Dashboard'} – ${brandName}${suffix}`} {!isKioskMode && } {!isKioskMode && ( diff --git a/packages/app/src/DBSearchPage.tsx b/packages/app/src/DBSearchPage.tsx index 732faa411f..818ee7e22c 100644 --- a/packages/app/src/DBSearchPage.tsx +++ b/packages/app/src/DBSearchPage.tsx @@ -109,6 +109,7 @@ import { SQLInlineEditorControlled } from '@/components/SQLEditor/SQLInlineEdito import { Tags } from '@/components/Tags'; import { TimePicker } from '@/components/TimePicker'; import { IS_LOCAL_MODE } from '@/config'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { useAliasMapFromChartConfig } from '@/hooks/useChartConfig'; import { useExplainQuery } from '@/hooks/useExplainQuery'; import { useResolvedSourceParam } from '@/hooks/useResolvedSourceParam'; @@ -1007,6 +1008,7 @@ export function useSearchTelemetry({ export function DBSearchPage() { const brandName = useBrandDisplayName(); + const suffix = getTitleSuffix(); const defaultTimeRange = useDefaultTimeRange('Past 15m'); // Next router is laggy behind window.location, which causes race @@ -2188,9 +2190,7 @@ export function DBSearchPage() { data-testid="search-page" > - - {savedSearch ? `${savedSearch.name} Search` : 'Search'} - {brandName} - + {`${savedSearch ? `${savedSearch.name} Search` : 'Search'} - ${brandName}${suffix}`} {!IS_LOCAL_MODE && isAlertModalOpen && ( ( <> - Service Map - {brandName} + {`Service Map - ${brandName}${suffix}`} ), - [brandName], + [brandName, suffix], ); const sourceSelect = source ? ( diff --git a/packages/app/src/KubernetesDashboardPage.tsx b/packages/app/src/KubernetesDashboardPage.tsx index 7897d8a548..b302c4fabc 100644 --- a/packages/app/src/KubernetesDashboardPage.tsx +++ b/packages/app/src/KubernetesDashboardPage.tsx @@ -43,6 +43,7 @@ import { useVirtualizer } from '@tanstack/react-virtual'; import { PageLayout } from '@/components/PageLayout'; import { TimePicker } from '@/components/TimePicker'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { useResolvedSourceParam } from '@/hooks/useResolvedSourceParam'; import { useVirtualList } from '@/hooks/useVirtualList'; @@ -1050,6 +1051,7 @@ const DEFAULT_INTERVAL = 'Past 1h'; function KubernetesDashboardPage() { const defaultTimeRange = useDefaultTimeRange(DEFAULT_INTERVAL); const brandName = useBrandDisplayName(); + const suffix = getTitleSuffix(); const { data: sources } = useSources(); const [_logSourceId, setLogSourceId] = useQueryState('logSource'); @@ -1378,7 +1380,7 @@ function KubernetesDashboardPage() { const dashboardBody = ( <> - Kubernetes Dashboard – {brandName} + {`Kubernetes Dashboard – ${brandName}${suffix}`} {metricSource && logSource && ( diff --git a/packages/app/src/ServicesDashboardPage/ServicesDashboardPage.tsx b/packages/app/src/ServicesDashboardPage/ServicesDashboardPage.tsx index 6c7515b0d3..a756f3ba5b 100644 --- a/packages/app/src/ServicesDashboardPage/ServicesDashboardPage.tsx +++ b/packages/app/src/ServicesDashboardPage/ServicesDashboardPage.tsx @@ -50,6 +50,7 @@ import { SourceSelectControlled } from '@/components/SourceSelect'; import { TimePicker } from '@/components/TimePicker'; import { IS_LOCAL_MODE } from '@/config'; import DashboardFilters from '@/DashboardFilters'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { useQueriedChartConfig } from '@/hooks/useChartConfig'; import { useDashboardRefresh } from '@/hooks/useDashboardRefresh'; import usePresetDashboardFilters from '@/hooks/usePresetDashboardFilters'; @@ -167,6 +168,7 @@ const DEFAULT_INTERVAL = 'Past 1h'; function ServicesDashboardPage() { const defaultTimeRange = useDefaultTimeRange(DEFAULT_INTERVAL); const brandName = useBrandDisplayName(); + const suffix = getTitleSuffix(); const [tab, setTab] = useQueryState( 'tab', parseAsStringEnum(['http', 'database', 'errors']).withDefault( @@ -313,7 +315,7 @@ function ServicesDashboardPage() { return ( - Services Dashboard – {brandName} + {`Services Dashboard – ${brandName}${suffix}`} diff --git a/packages/app/src/SessionsPage.tsx b/packages/app/src/SessionsPage.tsx index 270952ef1c..63893c9ccc 100644 --- a/packages/app/src/SessionsPage.tsx +++ b/packages/app/src/SessionsPage.tsx @@ -45,6 +45,7 @@ import { PageHeader } from '@/components/PageHeader'; import { PageLayout } from '@/components/PageLayout'; import { SourceSelectControlled } from '@/components/SourceSelect'; import { TimePicker } from '@/components/TimePicker'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { useDashboardRefresh } from '@/hooks/useDashboardRefresh'; import { useResolvedSourceParam } from '@/hooks/useResolvedSourceParam'; import { useDefaultTimeRange, useNewTimeQuery } from '@/timeQuery'; @@ -241,6 +242,7 @@ const DEFAULT_INTERVAL = 'Past 1h'; function SessionsPage() { const defaultTimeRange = useDefaultTimeRange(DEFAULT_INTERVAL); const brandName = useBrandDisplayName(); + const suffix = getTitleSuffix(); const [appliedConfig, setAppliedConfig] = useQueryStates(appliedConfigMap); // `?sessionSource=` accepts a source name as well as a source ID. The form // holds the resolved ID, so nothing downstream ever sees a name. @@ -397,7 +399,7 @@ function SessionsPage() { return ( <> - Client Sessions - {brandName} + {`Client Sessions - ${brandName}${suffix}`} {selectedSession != null && diff --git a/packages/app/src/TeamPage.tsx b/packages/app/src/TeamPage.tsx index 3880370159..8b051d3a06 100644 --- a/packages/app/src/TeamPage.tsx +++ b/packages/app/src/TeamPage.tsx @@ -24,6 +24,8 @@ import { IconUsers, } from '@tabler/icons-react'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; + import { PageHeader } from './components/PageHeader'; import ApiKeysSection from './components/TeamSettings/ApiKeysSection'; import ConnectionsSection from './components/TeamSettings/ConnectionsSection'; @@ -74,6 +76,7 @@ function TeamTabContent({ export default function TeamPage() { const brandName = useBrandDisplayName(); + const suffix = getTitleSuffix(); const router = useRouter(); const { data: team, refetch: refetchTeam, isLoading } = api.useTeam(); const setTeamName = api.useSetTeamName(); @@ -269,7 +272,7 @@ export default function TeamPage() { return (
- My Team - {brandName} + {`My Team - ${brandName}${suffix}`}
diff --git a/packages/app/src/components/Dashboards/DashboardTemplatesPage.tsx b/packages/app/src/components/Dashboards/DashboardTemplatesPage.tsx index 27a0bc7dd6..9d6dbc0f5e 100644 --- a/packages/app/src/components/Dashboards/DashboardTemplatesPage.tsx +++ b/packages/app/src/components/Dashboards/DashboardTemplatesPage.tsx @@ -14,11 +14,13 @@ import { import { IconUpload } from '@tabler/icons-react'; import { DASHBOARD_TEMPLATES } from '@/dashboardTemplates'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { withAppNav } from '@/layout'; import { useBrandDisplayName } from '@/theme/ThemeProvider'; export default function DashboardTemplatesPage() { const brandName = useBrandDisplayName(); + const suffix = getTitleSuffix(); const templatesByTag = useMemo(() => { const groups = new Map(); @@ -44,7 +46,7 @@ export default function DashboardTemplatesPage() { return (
- Dashboard Templates - {brandName} + {`Dashboard Templates - ${brandName}${suffix}`} diff --git a/packages/app/src/components/Dashboards/DashboardsListPage.tsx b/packages/app/src/components/Dashboards/DashboardsListPage.tsx index 2a4b62e284..557e50076c 100644 --- a/packages/app/src/components/Dashboards/DashboardsListPage.tsx +++ b/packages/app/src/components/Dashboards/DashboardsListPage.tsx @@ -54,6 +54,7 @@ import { useDeleteDashboard, } from '@/dashboard'; import { useFavorites } from '@/favorites'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { withAppNav } from '@/layout'; import { useBrandDisplayName } from '@/theme/ThemeProvider'; import { useConfirm } from '@/useConfirm'; @@ -98,6 +99,7 @@ const PRESET_DASHBOARDS = [ export default function DashboardsListPage() { const brandName = useBrandDisplayName(); + const suffix = getTitleSuffix(); const { data: dashboards, isLoading, isError } = useDashboards(); const { data: me, isPending: isMePending } = api.useMe(); const confirm = useConfirm(); @@ -218,7 +220,7 @@ export default function DashboardsListPage() { style={{ display: 'flex', flexDirection: 'column', minHeight: '100%' }} > - Dashboards - {brandName} + {`Dashboards - ${brandName}${suffix}`} - Saved Searches - {brandName} + {`Saved Searches - ${brandName}${suffix}`} ({ INSTANCE_LABEL: '' })); + +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; + +describe('getTitleSuffix (INSTANCE_LABEL unset)', () => { + it('returns an empty suffix', () => { + const { result } = renderHook(() => getTitleSuffix()); + expect(result.current).toBe(''); + }); +}); diff --git a/packages/app/src/hooks/__tests__/getTitleSuffix.test.tsx b/packages/app/src/hooks/__tests__/getTitleSuffix.test.tsx new file mode 100644 index 0000000000..6bb93c8ec5 --- /dev/null +++ b/packages/app/src/hooks/__tests__/getTitleSuffix.test.tsx @@ -0,0 +1,12 @@ +import { renderHook } from '@testing-library/react'; + +jest.mock('@/config', () => ({ INSTANCE_LABEL: 'UK' })); + +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; + +describe('getTitleSuffix', () => { + it('returns the suffix for a page to compose into its own title', () => { + const { result } = renderHook(() => getTitleSuffix()); + expect(result.current).toBe(' UK'); + }); +}); diff --git a/packages/app/src/hooks/__tests__/getTitleSuffix.whitespace.test.tsx b/packages/app/src/hooks/__tests__/getTitleSuffix.whitespace.test.tsx new file mode 100644 index 0000000000..6a6e29dd38 --- /dev/null +++ b/packages/app/src/hooks/__tests__/getTitleSuffix.whitespace.test.tsx @@ -0,0 +1,12 @@ +import { renderHook } from '@testing-library/react'; + +jest.mock('@/config', () => ({ INSTANCE_LABEL: 'EU West' })); + +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; + +describe('getTitleSuffix (label contains an internal whitespace run)', () => { + it('collapses the run to a single space', () => { + const { result } = renderHook(() => getTitleSuffix()); + expect(result.current).toBe(' EU West'); + }); +}); diff --git a/packages/app/src/hooks/__tests__/useTitleSuffix.no-label.test.tsx b/packages/app/src/hooks/__tests__/useTitleSuffix.no-label.test.tsx deleted file mode 100644 index 2a1f570020..0000000000 --- a/packages/app/src/hooks/__tests__/useTitleSuffix.no-label.test.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import { renderHook } from '@testing-library/react'; - -jest.mock('@/config', () => ({ INSTANCE_LABEL: '' })); - -import { useTitleSuffix } from '@/hooks/useTitleSuffix'; - -describe('useTitleSuffix (INSTANCE_LABEL unset)', () => { - it('returns an empty suffix', () => { - const { result } = renderHook(() => useTitleSuffix()); - expect(result.current).toBe(''); - }); - - it('leaves the title untouched', () => { - document.title = 'Search - HyperDX'; - renderHook(() => useTitleSuffix()); - expect(document.title).toBe('Search - HyperDX'); - }); -}); diff --git a/packages/app/src/hooks/__tests__/useTitleSuffix.test.tsx b/packages/app/src/hooks/__tests__/useTitleSuffix.test.tsx deleted file mode 100644 index 5dc3b302dc..0000000000 --- a/packages/app/src/hooks/__tests__/useTitleSuffix.test.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import { renderHook } from '@testing-library/react'; - -jest.mock('@/config', () => ({ INSTANCE_LABEL: 'UK' })); - -import { useTitleSuffix } from '@/hooks/useTitleSuffix'; - -describe('useTitleSuffix', () => { - beforeEach(() => { - document.title = 'Search - HyperDX'; - }); - - it('returns the suffix for call sites that render their own title', () => { - const { result } = renderHook(() => useTitleSuffix()); - expect(result.current).toBe(' UK'); - }); - - it('also appends the instance label to the current title', () => { - renderHook(() => useTitleSuffix()); - expect(document.title).toBe('Search - HyperDX UK'); - }); - - it('keeps appending the label as the title changes on navigation', async () => { - renderHook(() => useTitleSuffix()); - document.title = 'Alerts - HyperDX'; - await new Promise(resolve => setTimeout(resolve, 0)); - expect(document.title).toBe('Alerts - HyperDX UK'); - }); - - it('does not double-append if the title already has the suffix', () => { - document.title = 'Search - HyperDX UK'; - renderHook(() => useTitleSuffix()); - expect(document.title).toBe('Search - HyperDX UK'); - }); - - it('stops observing after unmount', async () => { - const { unmount } = renderHook(() => useTitleSuffix()); - unmount(); - document.title = 'Alerts - HyperDX'; - await new Promise(resolve => setTimeout(resolve, 0)); - expect(document.title).toBe('Alerts - HyperDX'); - }); -}); diff --git a/packages/app/src/hooks/__tests__/useTitleSuffix.whitespace.test.tsx b/packages/app/src/hooks/__tests__/useTitleSuffix.whitespace.test.tsx deleted file mode 100644 index 42484a91e2..0000000000 --- a/packages/app/src/hooks/__tests__/useTitleSuffix.whitespace.test.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { renderHook } from '@testing-library/react'; - -// A double space is a value real config.ts can produce before its own -// collapsing, and is also what document.title would collapse on write - -// this is the case that actually breaks the endsWith-based dedup check, -// not a trailing space (which .trim() already handles upstream). -jest.mock('@/config', () => ({ INSTANCE_LABEL: 'EU West' })); - -import { useTitleSuffix } from '@/hooks/useTitleSuffix'; - -describe('useTitleSuffix (label contains an internal whitespace run)', () => { - it('collapses the run so the suffix matches what document.title will store', () => { - document.title = 'Search - HyperDX'; - const { result } = renderHook(() => useTitleSuffix()); - expect(result.current).toBe(' EU West'); - expect(document.title).toBe('Search - HyperDX EU West'); - }); - - it('does not double-append when the title already has the collapsed suffix', () => { - document.title = 'Search - HyperDX EU West'; - renderHook(() => useTitleSuffix()); - expect(document.title).toBe('Search - HyperDX EU West'); - }); -}); diff --git a/packages/app/src/hooks/getTitleSuffix.ts b/packages/app/src/hooks/getTitleSuffix.ts new file mode 100644 index 0000000000..2e49ca7c38 --- /dev/null +++ b/packages/app/src/hooks/getTitleSuffix.ts @@ -0,0 +1,17 @@ +import { INSTANCE_LABEL } from '@/config'; + +// Collapsed defensively (not just relying on config.ts) since document.title +// collapses whitespace runs, so the displayed suffix should match what the +// browser would store even if a caller passes a messier value some other way. +const LABEL = INSTANCE_LABEL.replace(/\s+/g, ' '); +const SUFFIX = LABEL ? ` ${LABEL}` : ''; + +/** + * Returns the instance-label suffix to append to a page's own `` + * (empty string when unset). Every page that renders a `<title>` composes it + * with this suffix directly - there's no global mechanism that reaches + * titles a page doesn't opt into. + */ +export function getTitleSuffix(): string { + return SUFFIX; +} diff --git a/packages/app/src/hooks/useTitleSuffix.ts b/packages/app/src/hooks/useTitleSuffix.ts deleted file mode 100644 index a72a93a2fb..0000000000 --- a/packages/app/src/hooks/useTitleSuffix.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { useEffect } from 'react'; - -import { INSTANCE_LABEL } from '@/config'; - -// Collapsed defensively (not just relying on config.ts) since document.title -// collapses whitespace runs on write, and the dedup check below needs its -// comparison string to match what the browser will actually store. -const LABEL = INSTANCE_LABEL.replace(/\s+/g, ' '); -const SUFFIX = LABEL ? ` ${LABEL}` : ''; - -/** - * Returns the instance-label suffix to append to `_app.tsx`'s own base - * `<title>` (empty string when unset). - * - * Also keeps the browser tab's title suffixed as a side effect, for the many - * existing pages that render their own `<title>X - {brandName}` and - * so override whatever `_app.tsx` renders — a MutationObserver is the only - * way to reach those without threading the suffix through every page. - */ -export function useTitleSuffix(): string { - useEffect(() => { - if (!SUFFIX) { - return; - } - const titleEl = document.querySelector('title'); - if (!titleEl) { - return; - } - // document.title strips trailing whitespace, so discard our own write's - // mutation record rather than trusting endsWith to stop the loop. - const applySuffix = () => { - if (document.title.endsWith(SUFFIX)) { - return; - } - document.title = `${document.title}${SUFFIX}`; - observer.takeRecords(); - }; - const observer = new MutationObserver(applySuffix); - applySuffix(); - observer.observe(titleEl, { - childList: true, - characterData: true, - subtree: true, - }); - return () => observer.disconnect(); - }, []); - - return SUFFIX; -} diff --git a/packages/app/src/llm/dashboard/LLMDashboardPage.tsx b/packages/app/src/llm/dashboard/LLMDashboardPage.tsx index 619e186ac6..b3752c44d1 100644 --- a/packages/app/src/llm/dashboard/LLMDashboardPage.tsx +++ b/packages/app/src/llm/dashboard/LLMDashboardPage.tsx @@ -32,6 +32,7 @@ import SearchWhereInput, { } from '@/components/SearchInput/SearchWhereInput'; import { SourceSelectControlled } from '@/components/SourceSelect'; import { TimePicker } from '@/components/TimePicker'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { withAppNav } from '@/layout'; import { useLLMDashboardExpressions, @@ -77,6 +78,7 @@ const queryParamMap = { function LLMDashboardPage() { const defaultTimeRange = useDefaultTimeRange(DEFAULT_INTERVAL); const brandName = useBrandDisplayName(); + const suffix = getTitleSuffix(); const [rawTab, setTab] = useQueryState( 'tab', @@ -212,7 +214,7 @@ function LLMDashboardPage() { return ( - LLM Dashboard – {brandName} + {`LLM Dashboard – ${brandName}${suffix}`} From f7457940d3901363693f00dbbc296d9649b3d3bd Mon Sep 17 00:00:00 2001 From: arj22 Date: Mon, 5 Oct 2026 23:22:16 -0500 Subject: [PATCH 13/20] fix: address review findings on the observer-removal commit Fix a real regression: /login, /register, and /join-team set their titles via NextSeo, not a plain tag, so they never got the instance-label suffix once the MutationObserver (which caught title changes regardless of mechanism) was removed. Append it directly. Also: drop the now-pointless changeset describing removal of a MutationObserver that was added and removed within this same unreleased PR, and fix two comments left over from that observer's since-removed document.title comparison logic. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --- .changeset/instance-label-no-observer.md | 7 ------- packages/app/src/AuthPage.tsx | 5 ++++- packages/app/src/JoinTeamPage.tsx | 5 ++++- packages/app/src/config.ts | 3 +-- packages/app/src/hooks/getTitleSuffix.ts | 5 ++--- 5 files changed, 11 insertions(+), 14 deletions(-) delete mode 100644 .changeset/instance-label-no-observer.md diff --git a/.changeset/instance-label-no-observer.md b/.changeset/instance-label-no-observer.md deleted file mode 100644 index bfffe39320..0000000000 --- a/.changeset/instance-label-no-observer.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -'@hyperdx/app': patch ---- - -refactor: drop the instance-label MutationObserver, set the title directly on every page instead - -Every page that renders its own `<title>` now composes the instance-label suffix into it directly via `getTitleSuffix()`, removing the DOM-watching side effect that previously patched titles in after the fact. diff --git a/packages/app/src/AuthPage.tsx b/packages/app/src/AuthPage.tsx index 1aabb78088..87ee9990bd 100644 --- a/packages/app/src/AuthPage.tsx +++ b/packages/app/src/AuthPage.tsx @@ -14,6 +14,8 @@ import { } from '@mantine/core'; import { IconAt, IconLock } from '@tabler/icons-react'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; + import { useBrandDisplayName } from './theme/ThemeProvider'; import api from './api'; import * as config from './config'; @@ -57,7 +59,8 @@ export default function AuthPage({ action }: { action: 'register' | 'login' }) { const verificationSent = msg === 'verify'; - const title = `${brandName} - ${isRegister ? 'Sign up' : 'Login'}`; + const suffix = getTitleSuffix(); + const title = `${brandName} - ${isRegister ? 'Sign up' : 'Login'}${suffix}`; useEffect(() => { // If an OSS user accidentally lands on /register after already creating a team diff --git a/packages/app/src/JoinTeamPage.tsx b/packages/app/src/JoinTeamPage.tsx index e700478fc1..2278c4cc90 100644 --- a/packages/app/src/JoinTeamPage.tsx +++ b/packages/app/src/JoinTeamPage.tsx @@ -10,12 +10,15 @@ import { TextInput, } from '@mantine/core'; +import { getTitleSuffix } from '@/hooks/getTitleSuffix'; + import { useBrandDisplayName } from './theme/ThemeProvider'; import { PasswordCheck } from './PasswordCheck'; export default function JoinTeam() { const router = useRouter(); const brandName = useBrandDisplayName(); + const suffix = getTitleSuffix(); const { err, reason, token } = router.query; const [password, setPassword] = useState(''); @@ -31,7 +34,7 @@ export default function JoinTeam() { return ( <div className="AuthPage"> - <NextSeo title={`Join Team - ${brandName}`} /> + <NextSeo title={`Join Team - ${brandName}${suffix}`} /> <div className="d-flex align-items-center justify-content-center vh-100 p-2"> <div style={{ width: '26rem', maxWidth: '100%' }}> <div className="text-center mb-4"> diff --git a/packages/app/src/config.ts b/packages/app/src/config.ts index 88f142b312..fb08fe6f7f 100644 --- a/packages/app/src/config.ts +++ b/packages/app/src/config.ts @@ -85,8 +85,7 @@ export const IS_PROMQL_ENABLED = env('NEXT_PUBLIC_ENABLE_PROMQL') === 'true'; // Suffix for the tab title/sidebar pill. Shown in full in the page title; // only truncated visually (via CSS ellipsis) in the sidebar, where space is // constrained. Internal whitespace is collapsed so it displays consistently -// and so the tab-title suffix (which compares against document.title, where -// the browser collapses whitespace runs) can reliably detect its own suffix. +// wherever it's shown. export const INSTANCE_LABEL = (env('NEXT_PUBLIC_INSTANCE_LABEL') ?? '') .trim() .replace(/\s+/g, ' '); diff --git a/packages/app/src/hooks/getTitleSuffix.ts b/packages/app/src/hooks/getTitleSuffix.ts index 2e49ca7c38..8534bd9045 100644 --- a/packages/app/src/hooks/getTitleSuffix.ts +++ b/packages/app/src/hooks/getTitleSuffix.ts @@ -1,8 +1,7 @@ import { INSTANCE_LABEL } from '@/config'; -// Collapsed defensively (not just relying on config.ts) since document.title -// collapses whitespace runs, so the displayed suffix should match what the -// browser would store even if a caller passes a messier value some other way. +// Collapsed defensively (not just relying on config.ts) so the suffix looks +// clean even if a caller passes a messier value some other way. const LABEL = INSTANCE_LABEL.replace(/\s+/g, ' '); const SUFFIX = LABEL ? ` ${LABEL}` : ''; From b31ecf991b19cb4320ae0503f032e8725569e912 Mon Sep 17 00:00:00 2001 From: arj22 <anudeep@nightfall.ai> Date: Mon, 5 Oct 2026 23:35:27 -0500 Subject: [PATCH 14/20] Fold getTitleSuffix into a plain config constant, fix two regressions - Replace the hooks/getTitleSuffix() function (dead whitespace-collapse code, misleading "use" prefix once the MutationObserver was removed) with a plain INSTANCE_TITLE_SUFFIX constant in config.ts, and migrate all 20 call sites. - Fix AuthPage title ordering: suffix was appended after "Login"/"Sign up" instead of after the brand name, inconsistent with every other page. - Fix .logoLink stretching to fill empty header space and absorbing clicks there; it only needed min-width: 0 to shrink for ellipsis, not flex: 1 to grow. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --- packages/app/pages/_app.tsx | 10 ++++++---- packages/app/src/AlertDetailPage.tsx | 6 ++---- packages/app/src/AlertsPage.tsx | 5 ++--- packages/app/src/AuthPage.tsx | 6 +----- packages/app/src/CareersPage.tsx | 6 ++---- packages/app/src/ClickhousePage.tsx | 5 ++--- packages/app/src/DBChartPage.tsx | 6 ++---- packages/app/src/DBDashboardImportPage.tsx | 5 ++--- packages/app/src/DBDashboardPage.tsx | 5 ++--- packages/app/src/DBSearchPage.tsx | 6 ++---- packages/app/src/DBServiceMapPage.tsx | 8 +++----- packages/app/src/JoinTeamPage.tsx | 5 ++--- packages/app/src/KubernetesDashboardPage.tsx | 5 ++--- .../ServicesDashboardPage.tsx | 6 ++---- packages/app/src/SessionsPage.tsx | 5 ++--- packages/app/src/TeamPage.tsx | 7 ++----- .../config.instanceTitleSuffix.no-label.test.ts | 9 +++++++++ .../__tests__/config.instanceTitleSuffix.test.ts | 9 +++++++++ .../app/src/components/AppNav/AppNav.module.scss | 4 +++- packages/app/src/components/AppNav/AppNav.tsx | 2 +- .../Dashboards/DashboardTemplatesPage.tsx | 5 ++--- .../components/Dashboards/DashboardsListPage.tsx | 6 ++---- .../SavedSearches/SavedSearchesListPage.tsx | 5 ++--- packages/app/src/config.ts | 4 ++++ .../__tests__/getTitleSuffix.no-label.test.tsx | 12 ------------ .../src/hooks/__tests__/getTitleSuffix.test.tsx | 12 ------------ .../__tests__/getTitleSuffix.whitespace.test.tsx | 12 ------------ packages/app/src/hooks/getTitleSuffix.ts | 16 ---------------- .../app/src/llm/dashboard/LLMDashboardPage.tsx | 5 ++--- 29 files changed, 70 insertions(+), 127 deletions(-) create mode 100644 packages/app/src/__tests__/config.instanceTitleSuffix.no-label.test.ts create mode 100644 packages/app/src/__tests__/config.instanceTitleSuffix.test.ts delete mode 100644 packages/app/src/hooks/__tests__/getTitleSuffix.no-label.test.tsx delete mode 100644 packages/app/src/hooks/__tests__/getTitleSuffix.test.tsx delete mode 100644 packages/app/src/hooks/__tests__/getTitleSuffix.whitespace.test.tsx delete mode 100644 packages/app/src/hooks/getTitleSuffix.ts diff --git a/packages/app/pages/_app.tsx b/packages/app/pages/_app.tsx index eb46c87765..272f3f5a99 100644 --- a/packages/app/pages/_app.tsx +++ b/packages/app/pages/_app.tsx @@ -15,7 +15,11 @@ import { import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; import { DynamicFavicon } from '@/components/DynamicFavicon'; -import { IS_LOCAL_MODE, parseResourceAttributes } from '@/config'; +import { + INSTANCE_TITLE_SUFFIX, + IS_LOCAL_MODE, + parseResourceAttributes, +} from '@/config'; import { DEFAULT_FONT_VAR, FONT_VAR_MAP, @@ -23,7 +27,6 @@ import { } from '@/config/fonts'; import { ibmPlexMono, inter, roboto, robotoMono } from '@/fonts'; import { fetchServerVersion, installHdxDebug } from '@/hdxDebug'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { AppThemeProvider, useAppTheme } from '@/theme/ThemeProvider'; import { ThemeWrapper } from '@/ThemeWrapper'; import { NextApiConfigResponseData } from '@/types'; @@ -72,11 +75,10 @@ type AppPropsWithLayout = AppProps & { // Must be rendered inside AppThemeProvider to avoid hydration mismatch function AppHeadContent() { const { theme } = useAppTheme(); - const suffix = getTitleSuffix(); return ( <Head> - <title>{`${theme.displayName}${suffix}`} + {`${theme.displayName}${INSTANCE_TITLE_SUFFIX}`} diff --git a/packages/app/src/AlertDetailPage.tsx b/packages/app/src/AlertDetailPage.tsx index 05d2172e39..eafcbbfe5d 100644 --- a/packages/app/src/AlertDetailPage.tsx +++ b/packages/app/src/AlertDetailPage.tsx @@ -27,8 +27,7 @@ import { AlertStateBadge } from '@/components/alerts/AlertStateBadge'; import EmptyState from '@/components/EmptyState'; import { PageHeader } from '@/components/PageHeader'; import { TimePicker } from '@/components/TimePicker'; -import { IS_ALERT_DETAILS_ENABLED } from '@/config'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; +import { INSTANCE_TITLE_SUFFIX, IS_ALERT_DETAILS_ENABLED } from '@/config'; import { getAlertSourceLabel, getAlertSourceUrl } from '@/utils/alerts'; import { useBrandDisplayName } from './theme/ThemeProvider'; @@ -225,7 +224,6 @@ function AlertDetailBody({ alert }: { alert: AlertsPageItem }) { export default function AlertDetailPage() { const brandName = useBrandDisplayName(); - const suffix = getTitleSuffix(); const router = useRouter(); const alertId = typeof router.query.alertId === 'string' ? router.query.alertId : undefined; @@ -251,7 +249,7 @@ export default function AlertDetailPage() { style={{ display: 'flex', flexDirection: 'column', height: '100%' }} > - {`${alert ? `${alert.displayName} - Alerts` : 'Alerts'} - ${brandName}${suffix}`} + {`${alert ? `${alert.displayName} - Alerts` : 'Alerts'} - ${brandName}${INSTANCE_TITLE_SUFFIX}`} {isLoading && ( diff --git a/packages/app/src/AlertsPage.tsx b/packages/app/src/AlertsPage.tsx index f58e3df1af..838060b44e 100644 --- a/packages/app/src/AlertsPage.tsx +++ b/packages/app/src/AlertsPage.tsx @@ -19,7 +19,7 @@ import { AlertCardList } from '@/components/alerts/AlertCardList'; import { AlertsFilterBar } from '@/components/alerts/AlertsFilterBar'; import EmptyState from '@/components/EmptyState'; import { PageHeader } from '@/components/PageHeader'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; +import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { ALERT_STATE_FILTER_OPTIONS } from '@/utils/alerts'; import { useBrandDisplayName } from './theme/ThemeProvider'; @@ -30,7 +30,6 @@ const SEARCH_DEBOUNCE_MS = 300; export default function AlertsPage() { const brandName = useBrandDisplayName(); - const suffix = getTitleSuffix(); const mounted = useMounted(); const [search, setSearch] = useQueryState('search'); @@ -116,7 +115,7 @@ export default function AlertsPage() { style={{ display: 'flex', flexDirection: 'column', minHeight: '100%' }} > - {`Alerts - ${brandName}${suffix}`} + {`Alerts - ${brandName}${INSTANCE_TITLE_SUFFIX}`}
{ // If an OSS user accidentally lands on /register after already creating a team diff --git a/packages/app/src/CareersPage.tsx b/packages/app/src/CareersPage.tsx index c48249d0d7..6344202a15 100644 --- a/packages/app/src/CareersPage.tsx +++ b/packages/app/src/CareersPage.tsx @@ -13,8 +13,7 @@ import { } from '@mantine/core'; import { useQuery } from '@tanstack/react-query'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; - +import { INSTANCE_TITLE_SUFFIX } from '@/config'; interface GreenhouseJob { id: number; title: string; @@ -82,7 +81,6 @@ function useGreenhouseJobs() { } export default function CareersPage() { - const suffix = getTitleSuffix(); const { data: commitsData, isLoading: commitsLoading } = useRecentCommits(); const { data, isLoading, isError } = useGreenhouseJobs(); @@ -94,7 +92,7 @@ export default function CareersPage() { return ( - {`Careers | HyperDX${suffix}`} + {`Careers | HyperDX${INSTANCE_TITLE_SUFFIX}`} diff --git a/packages/app/src/ClickhousePage.tsx b/packages/app/src/ClickhousePage.tsx index 76d76c3d3c..a5412233fb 100644 --- a/packages/app/src/ClickhousePage.tsx +++ b/packages/app/src/ClickhousePage.tsx @@ -36,7 +36,7 @@ import { ConnectionSelectControlled } from '@/components/ConnectionSelect'; import { DBTimeChart } from '@/components/DBTimeChart'; import { PageLayout } from '@/components/PageLayout'; import { TimePicker } from '@/components/TimePicker'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; +import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { withAppNavForSurface } from '@/layout'; import { ChartCard } from './components/charts/ChartCard'; @@ -493,7 +493,6 @@ const DEFAULT_INTERVAL = 'Past 1h'; function ClickhousePage() { const defaultTimeRange = useDefaultTimeRange(DEFAULT_INTERVAL); const brandName = useBrandDisplayName(); - const suffix = getTitleSuffix(); const { colorScheme } = useMantineColorScheme(); const { data: connections } = useConnections(); const [_connection, setConnection] = useQueryState('connection'); @@ -646,7 +645,7 @@ function ClickhousePage() { content={ <> <Head> - <title>{`ClickHouse Dashboard – ${brandName}${suffix}`} + {`ClickHouse Dashboard – ${brandName}${INSTANCE_TITLE_SUFFIX}`} - {`Chart Explorer - ${brandName}${suffix}`} + {`Chart Explorer - ${brandName}${INSTANCE_TITLE_SUFFIX}`} - {`Import Dashboard - ${brandName}${suffix}`} + {`Import Dashboard - ${brandName}${INSTANCE_TITLE_SUFFIX}`} diff --git a/packages/app/src/DBDashboardPage.tsx b/packages/app/src/DBDashboardPage.tsx index 0719d585dc..3c046821e6 100644 --- a/packages/app/src/DBDashboardPage.tsx +++ b/packages/app/src/DBDashboardPage.tsx @@ -153,6 +153,7 @@ import { parseTimeRangeInput, timeRangeInputToSeconds, } from '@/components/TimePicker/utils'; +import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { Dashboard, type Tile, @@ -160,7 +161,6 @@ import { useDashboards, useDeleteDashboard, } from '@/dashboard'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { useAlertAnnotations } from '@/hooks/useAlertAnnotations'; import useDashboardContainers, { TabDeleteAction, @@ -1889,7 +1889,6 @@ function DBDashboardPage({ isSetting: isSavingDashboard, } = dashboardProps; const brandName = useBrandDisplayName(); - const suffix = getTitleSuffix(); const confirm = useConfirm(); const { userPreferences: { isUTC }, @@ -3225,7 +3224,7 @@ function DBDashboardPage({ const dashboardBody = ( <> - {`${dashboard?.name ? dashboard.name : 'Dashboard'} – ${brandName}${suffix}`} + {`${dashboard?.name ? dashboard.name : 'Dashboard'} – ${brandName}${INSTANCE_TITLE_SUFFIX}`} {!isKioskMode && } {!isKioskMode && ( diff --git a/packages/app/src/DBSearchPage.tsx b/packages/app/src/DBSearchPage.tsx index c861969984..195492437e 100644 --- a/packages/app/src/DBSearchPage.tsx +++ b/packages/app/src/DBSearchPage.tsx @@ -109,8 +109,7 @@ import { SourceSelectControlled } from '@/components/SourceSelect'; import { SQLInlineEditorControlled } from '@/components/SQLEditor/SQLInlineEditor'; import { Tags } from '@/components/Tags'; import { TimePicker } from '@/components/TimePicker'; -import { IS_LOCAL_MODE } from '@/config'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; +import { INSTANCE_TITLE_SUFFIX, IS_LOCAL_MODE } from '@/config'; import { useAliasMapFromChartConfig } from '@/hooks/useChartConfig'; import { useExplainQuery } from '@/hooks/useExplainQuery'; import { useResolvedSourceParam } from '@/hooks/useResolvedSourceParam'; @@ -1040,7 +1039,6 @@ function DBSearchPageContent() { // query-state hooks without the wrapper, and must see the current path. const savedSearchId = getSavedSearchIdFromPath(); const brandName = useBrandDisplayName(); - const suffix = getTitleSuffix(); const defaultTimeRange = useDefaultTimeRange('Past 15m'); const [rawSearchedConfig, setSearchedConfig] = useQueryStates(queryStateMap); @@ -2217,7 +2215,7 @@ function DBSearchPageContent() { data-testid="search-page" > - {`${savedSearch ? `${savedSearch.name} Search` : 'Search'} - ${brandName}${suffix}`} + {`${savedSearch ? `${savedSearch.name} Search` : 'Search'} - ${brandName}${INSTANCE_TITLE_SUFFIX}`} {!IS_LOCAL_MODE && isAlertModalOpen && ( ( <> - {`Service Map - ${brandName}${suffix}`} + {`Service Map - ${brandName}${INSTANCE_TITLE_SUFFIX}`} ), - [brandName, suffix], + [brandName], ); const sourceSelect = source ? ( diff --git a/packages/app/src/JoinTeamPage.tsx b/packages/app/src/JoinTeamPage.tsx index 2278c4cc90..0fb3c86f02 100644 --- a/packages/app/src/JoinTeamPage.tsx +++ b/packages/app/src/JoinTeamPage.tsx @@ -10,7 +10,7 @@ import { TextInput, } from '@mantine/core'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; +import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { useBrandDisplayName } from './theme/ThemeProvider'; import { PasswordCheck } from './PasswordCheck'; @@ -18,7 +18,6 @@ import { PasswordCheck } from './PasswordCheck'; export default function JoinTeam() { const router = useRouter(); const brandName = useBrandDisplayName(); - const suffix = getTitleSuffix(); const { err, reason, token } = router.query; const [password, setPassword] = useState(''); @@ -34,7 +33,7 @@ export default function JoinTeam() { return (
- +
diff --git a/packages/app/src/KubernetesDashboardPage.tsx b/packages/app/src/KubernetesDashboardPage.tsx index 9aae8f4213..918af8c2e2 100644 --- a/packages/app/src/KubernetesDashboardPage.tsx +++ b/packages/app/src/KubernetesDashboardPage.tsx @@ -43,7 +43,7 @@ import { useVirtualizer } from '@tanstack/react-virtual'; import { PageLayout } from '@/components/PageLayout'; import { TimePicker } from '@/components/TimePicker'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; +import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { useResolvedSourceParam } from '@/hooks/useResolvedSourceParam'; import { useVirtualList } from '@/hooks/useVirtualList'; @@ -1051,7 +1051,6 @@ const DEFAULT_INTERVAL = 'Past 1h'; function KubernetesDashboardPage() { const defaultTimeRange = useDefaultTimeRange(DEFAULT_INTERVAL); const brandName = useBrandDisplayName(); - const suffix = getTitleSuffix(); const { data: sources } = useSources(); const [_logSourceId, setLogSourceId] = useQueryState('logSource'); @@ -1380,7 +1379,7 @@ function KubernetesDashboardPage() { const dashboardBody = ( <> - {`Kubernetes Dashboard – ${brandName}${suffix}`} + {`Kubernetes Dashboard – ${brandName}${INSTANCE_TITLE_SUFFIX}`} {metricSource && logSource && ( diff --git a/packages/app/src/ServicesDashboardPage/ServicesDashboardPage.tsx b/packages/app/src/ServicesDashboardPage/ServicesDashboardPage.tsx index 25b0159a29..896ba5b918 100644 --- a/packages/app/src/ServicesDashboardPage/ServicesDashboardPage.tsx +++ b/packages/app/src/ServicesDashboardPage/ServicesDashboardPage.tsx @@ -48,9 +48,8 @@ import ServiceDashboardDbQuerySidePanel from '@/components/ServiceDashboardDbQue import ServiceDashboardEndpointSidePanel from '@/components/ServiceDashboardEndpointSidePanel'; import { SourceSelectControlled } from '@/components/SourceSelect'; import { TimePicker } from '@/components/TimePicker'; -import { IS_LOCAL_MODE } from '@/config'; +import { INSTANCE_TITLE_SUFFIX, IS_LOCAL_MODE } from '@/config'; import DashboardFilters from '@/DashboardFilters'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { useQueriedChartConfig } from '@/hooks/useChartConfig'; import { useDashboardRefresh } from '@/hooks/useDashboardRefresh'; import usePresetDashboardFilters from '@/hooks/usePresetDashboardFilters'; @@ -168,7 +167,6 @@ const DEFAULT_INTERVAL = 'Past 1h'; function ServicesDashboardPage() { const defaultTimeRange = useDefaultTimeRange(DEFAULT_INTERVAL); const brandName = useBrandDisplayName(); - const suffix = getTitleSuffix(); const [tab, setTab] = useQueryState( 'tab', parseAsStringEnum(['http', 'database', 'errors']).withDefault( @@ -315,7 +313,7 @@ function ServicesDashboardPage() { return ( - {`Services Dashboard – ${brandName}${suffix}`} + {`Services Dashboard – ${brandName}${INSTANCE_TITLE_SUFFIX}`} diff --git a/packages/app/src/SessionsPage.tsx b/packages/app/src/SessionsPage.tsx index ef3d018b9c..5a6ef6c0e9 100644 --- a/packages/app/src/SessionsPage.tsx +++ b/packages/app/src/SessionsPage.tsx @@ -45,7 +45,7 @@ import { PageHeader } from '@/components/PageHeader'; import { PageLayout } from '@/components/PageLayout'; import { SourceSelectControlled } from '@/components/SourceSelect'; import { TimePicker } from '@/components/TimePicker'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; +import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { useDashboardRefresh } from '@/hooks/useDashboardRefresh'; import { useResolvedSourceParam } from '@/hooks/useResolvedSourceParam'; import { useDefaultTimeRange, useNewTimeQuery } from '@/timeQuery'; @@ -242,7 +242,6 @@ const DEFAULT_INTERVAL = 'Past 1h'; function SessionsPage() { const defaultTimeRange = useDefaultTimeRange(DEFAULT_INTERVAL); const brandName = useBrandDisplayName(); - const suffix = getTitleSuffix(); const [appliedConfig, setAppliedConfig] = useQueryStates(appliedConfigMap); // `?sessionSource=` accepts a source name as well as a source ID. The form // holds the resolved ID, so nothing downstream ever sees a name. @@ -399,7 +398,7 @@ function SessionsPage() { return ( <> - {`Client Sessions - ${brandName}${suffix}`} + {`Client Sessions - ${brandName}${INSTANCE_TITLE_SUFFIX}`} {selectedSession != null && diff --git a/packages/app/src/TeamPage.tsx b/packages/app/src/TeamPage.tsx index 8b051d3a06..23f8ec1362 100644 --- a/packages/app/src/TeamPage.tsx +++ b/packages/app/src/TeamPage.tsx @@ -24,8 +24,6 @@ import { IconUsers, } from '@tabler/icons-react'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; - import { PageHeader } from './components/PageHeader'; import ApiKeysSection from './components/TeamSettings/ApiKeysSection'; import ConnectionsSection from './components/TeamSettings/ConnectionsSection'; @@ -38,7 +36,7 @@ import TeamMembersSection from './components/TeamSettings/TeamMembersSection'; import TeamQueryConfigSection from './components/TeamSettings/TeamQueryConfigSection'; import { useBrandDisplayName } from './theme/ThemeProvider'; import api from './api'; -import { IS_IAC_EXPORT_ENABLED } from './config'; +import { INSTANCE_TITLE_SUFFIX, IS_IAC_EXPORT_ENABLED } from './config'; import { APP_CONTENT_SCROLL_CONTAINER_ID, withAppNav } from './layout'; type TeamTab = { @@ -76,7 +74,6 @@ function TeamTabContent({ export default function TeamPage() { const brandName = useBrandDisplayName(); - const suffix = getTitleSuffix(); const router = useRouter(); const { data: team, refetch: refetchTeam, isLoading } = api.useTeam(); const setTeamName = api.useSetTeamName(); @@ -272,7 +269,7 @@ export default function TeamPage() { return (
- {`My Team - ${brandName}${suffix}`} + {`My Team - ${brandName}${INSTANCE_TITLE_SUFFIX}`}
diff --git a/packages/app/src/__tests__/config.instanceTitleSuffix.no-label.test.ts b/packages/app/src/__tests__/config.instanceTitleSuffix.no-label.test.ts new file mode 100644 index 0000000000..7e24215b02 --- /dev/null +++ b/packages/app/src/__tests__/config.instanceTitleSuffix.no-label.test.ts @@ -0,0 +1,9 @@ +jest.mock('next-runtime-env', () => ({ env: () => undefined })); + +import { INSTANCE_TITLE_SUFFIX } from '@/config'; + +describe('INSTANCE_TITLE_SUFFIX (INSTANCE_LABEL unset)', () => { + it('is empty', () => { + expect(INSTANCE_TITLE_SUFFIX).toBe(''); + }); +}); diff --git a/packages/app/src/__tests__/config.instanceTitleSuffix.test.ts b/packages/app/src/__tests__/config.instanceTitleSuffix.test.ts new file mode 100644 index 0000000000..c46f8d3fea --- /dev/null +++ b/packages/app/src/__tests__/config.instanceTitleSuffix.test.ts @@ -0,0 +1,9 @@ +jest.mock('next-runtime-env', () => ({ env: () => 'UK' })); + +import { INSTANCE_TITLE_SUFFIX } from '@/config'; + +describe('INSTANCE_TITLE_SUFFIX', () => { + it('is the label with a leading space, ready to append to a title', () => { + expect(INSTANCE_TITLE_SUFFIX).toBe(' UK'); + }); +}); diff --git a/packages/app/src/components/AppNav/AppNav.module.scss b/packages/app/src/components/AppNav/AppNav.module.scss index 45afbe6344..39c583510d 100644 --- a/packages/app/src/components/AppNav/AppNav.module.scss +++ b/packages/app/src/components/AppNav/AppNav.module.scss @@ -109,8 +109,10 @@ $transition-slow: 0.2s ease; align-items: center; justify-content: center; color: var(--color-text); + // Shrinkable (not growable) so a long label can still ellipsis when the + // sidebar is narrow, without stretching this link to fill the empty + // header space next to it (that space shouldn't be part of the link). min-width: 0; - flex: 1; } .logoIconWrapper { diff --git a/packages/app/src/components/AppNav/AppNav.tsx b/packages/app/src/components/AppNav/AppNav.tsx index 36e1bd9e2f..2d9bccd8a5 100644 --- a/packages/app/src/components/AppNav/AppNav.tsx +++ b/packages/app/src/components/AppNav/AppNav.tsx @@ -369,7 +369,7 @@ export default function AppNav({ fixed = false }: { fixed?: boolean }) { gap="xs" align="center" wrap="nowrap" - style={{ minWidth: 0, flex: 1 }} + style={{ minWidth: 0 }} > {wordmark} {/* Label and UTC badge are mutually exclusive - showing both diff --git a/packages/app/src/components/Dashboards/DashboardTemplatesPage.tsx b/packages/app/src/components/Dashboards/DashboardTemplatesPage.tsx index 9d6dbc0f5e..1591f38519 100644 --- a/packages/app/src/components/Dashboards/DashboardTemplatesPage.tsx +++ b/packages/app/src/components/Dashboards/DashboardTemplatesPage.tsx @@ -13,14 +13,13 @@ import { } from '@mantine/core'; import { IconUpload } from '@tabler/icons-react'; +import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { DASHBOARD_TEMPLATES } from '@/dashboardTemplates'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { withAppNav } from '@/layout'; import { useBrandDisplayName } from '@/theme/ThemeProvider'; export default function DashboardTemplatesPage() { const brandName = useBrandDisplayName(); - const suffix = getTitleSuffix(); const templatesByTag = useMemo(() => { const groups = new Map(); @@ -46,7 +45,7 @@ export default function DashboardTemplatesPage() { return (
- {`Dashboard Templates - ${brandName}${suffix}`} + {`Dashboard Templates - ${brandName}${INSTANCE_TITLE_SUFFIX}`} diff --git a/packages/app/src/components/Dashboards/DashboardsListPage.tsx b/packages/app/src/components/Dashboards/DashboardsListPage.tsx index 557e50076c..47004aa99f 100644 --- a/packages/app/src/components/Dashboards/DashboardsListPage.tsx +++ b/packages/app/src/components/Dashboards/DashboardsListPage.tsx @@ -46,7 +46,7 @@ import { FavoriteButton } from '@/components/FavoriteButton'; import { ListingCard } from '@/components/ListingCard'; import { ListingRow } from '@/components/ListingListRow'; import { PageHeader } from '@/components/PageHeader'; -import { IS_K8S_DASHBOARD_ENABLED } from '@/config'; +import { INSTANCE_TITLE_SUFFIX, IS_K8S_DASHBOARD_ENABLED } from '@/config'; import { type Dashboard, useCreateDashboard, @@ -54,7 +54,6 @@ import { useDeleteDashboard, } from '@/dashboard'; import { useFavorites } from '@/favorites'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; import { withAppNav } from '@/layout'; import { useBrandDisplayName } from '@/theme/ThemeProvider'; import { useConfirm } from '@/useConfirm'; @@ -99,7 +98,6 @@ const PRESET_DASHBOARDS = [ export default function DashboardsListPage() { const brandName = useBrandDisplayName(); - const suffix = getTitleSuffix(); const { data: dashboards, isLoading, isError } = useDashboards(); const { data: me, isPending: isMePending } = api.useMe(); const confirm = useConfirm(); @@ -220,7 +218,7 @@ export default function DashboardsListPage() { style={{ display: 'flex', flexDirection: 'column', minHeight: '100%' }} > - {`Dashboards - ${brandName}${suffix}`} + {`Dashboards - ${brandName}${INSTANCE_TITLE_SUFFIX}`} - {`Saved Searches - ${brandName}${suffix}`} + {`Saved Searches - ${brandName}${INSTANCE_TITLE_SUFFIX}`} ({ INSTANCE_LABEL: '' })); - -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; - -describe('getTitleSuffix (INSTANCE_LABEL unset)', () => { - it('returns an empty suffix', () => { - const { result } = renderHook(() => getTitleSuffix()); - expect(result.current).toBe(''); - }); -}); diff --git a/packages/app/src/hooks/__tests__/getTitleSuffix.test.tsx b/packages/app/src/hooks/__tests__/getTitleSuffix.test.tsx deleted file mode 100644 index 6bb93c8ec5..0000000000 --- a/packages/app/src/hooks/__tests__/getTitleSuffix.test.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { renderHook } from '@testing-library/react'; - -jest.mock('@/config', () => ({ INSTANCE_LABEL: 'UK' })); - -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; - -describe('getTitleSuffix', () => { - it('returns the suffix for a page to compose into its own title', () => { - const { result } = renderHook(() => getTitleSuffix()); - expect(result.current).toBe(' UK'); - }); -}); diff --git a/packages/app/src/hooks/__tests__/getTitleSuffix.whitespace.test.tsx b/packages/app/src/hooks/__tests__/getTitleSuffix.whitespace.test.tsx deleted file mode 100644 index 6a6e29dd38..0000000000 --- a/packages/app/src/hooks/__tests__/getTitleSuffix.whitespace.test.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { renderHook } from '@testing-library/react'; - -jest.mock('@/config', () => ({ INSTANCE_LABEL: 'EU West' })); - -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; - -describe('getTitleSuffix (label contains an internal whitespace run)', () => { - it('collapses the run to a single space', () => { - const { result } = renderHook(() => getTitleSuffix()); - expect(result.current).toBe(' EU West'); - }); -}); diff --git a/packages/app/src/hooks/getTitleSuffix.ts b/packages/app/src/hooks/getTitleSuffix.ts deleted file mode 100644 index 8534bd9045..0000000000 --- a/packages/app/src/hooks/getTitleSuffix.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { INSTANCE_LABEL } from '@/config'; - -// Collapsed defensively (not just relying on config.ts) so the suffix looks -// clean even if a caller passes a messier value some other way. -const LABEL = INSTANCE_LABEL.replace(/\s+/g, ' '); -const SUFFIX = LABEL ? ` ${LABEL}` : ''; - -/** - * Returns the instance-label suffix to append to a page's own `` - * (empty string when unset). Every page that renders a `<title>` composes it - * with this suffix directly - there's no global mechanism that reaches - * titles a page doesn't opt into. - */ -export function getTitleSuffix(): string { - return SUFFIX; -} diff --git a/packages/app/src/llm/dashboard/LLMDashboardPage.tsx b/packages/app/src/llm/dashboard/LLMDashboardPage.tsx index c0de85cc25..da8f6ca10f 100644 --- a/packages/app/src/llm/dashboard/LLMDashboardPage.tsx +++ b/packages/app/src/llm/dashboard/LLMDashboardPage.tsx @@ -32,7 +32,7 @@ import SearchWhereInput, { } from '@/components/SearchInput/SearchWhereInput'; import { SourceSelectControlled } from '@/components/SourceSelect'; import { TimePicker } from '@/components/TimePicker'; -import { getTitleSuffix } from '@/hooks/getTitleSuffix'; +import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { withAppNavForSurface } from '@/layout'; import { useLLMDashboardExpressions, @@ -78,7 +78,6 @@ const queryParamMap = { function LLMDashboardPage() { const defaultTimeRange = useDefaultTimeRange(DEFAULT_INTERVAL); const brandName = useBrandDisplayName(); - const suffix = getTitleSuffix(); const [rawTab, setTab] = useQueryState( 'tab', @@ -214,7 +213,7 @@ function LLMDashboardPage() { return ( <Box p="sm" data-testid="llm-dashboard-page"> <Head> - <title>{`LLM Dashboard – ${brandName}${suffix}`} + {`LLM Dashboard – ${brandName}${INSTANCE_TITLE_SUFFIX}`} From 261ccb83a86c03b9668642a1d0a35ab9ccf8827b Mon Sep 17 00:00:00 2001 From: arj22 Date: Tue, 6 Oct 2026 07:12:29 -0500 Subject: [PATCH 15/20] Shrink InstanceLabel's maxWidth to guarantee it fits the sidebar header flex-wrap:wrap on .header decides line breaks using each item's pre-shrink hypothetical size, so a label hitting the old 120px cap could still wrap the collapse button onto a clipped second line even though min-width:0 lets it shrink afterwards. 80px leaves enough margin against the wordmark + gap + collapse button's width. Co-Authored-By: Claude Sonnet 5 --- packages/app/src/components/AppNav/InstanceLabel.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/app/src/components/AppNav/InstanceLabel.tsx b/packages/app/src/components/AppNav/InstanceLabel.tsx index dd71c5bcb9..eaf755891e 100644 --- a/packages/app/src/components/AppNav/InstanceLabel.tsx +++ b/packages/app/src/components/AppNav/InstanceLabel.tsx @@ -18,7 +18,13 @@ export function InstanceLabel({ fallback = null }: { fallback?: ReactNode }) { fw="normal" tt="none" title={INSTANCE_LABEL} - style={{ minWidth: 0, maxWidth: 120 }} + // Capped well under the sidebar's available width (wordmark + gap + + // collapse button) so a long label can't push the header's content past + // one line: `.header`'s flex-wrap:wrap decides line breaks using each + // item's pre-shrink hypothetical size, not its post-shrink size, so + // min-width:0 alone doesn't prevent a maxed-out badge from wrapping the + // collapse button onto a second, clipped line. + style={{ minWidth: 0, maxWidth: 80 }} > {INSTANCE_LABEL} From 70f0be14abb767192b70eb5a4a12f2ca7dd47bdc Mon Sep 17 00:00:00 2001 From: arj22 Date: Tue, 6 Oct 2026 07:20:05 -0500 Subject: [PATCH 16/20] Mock env() by key in instance-label tests env: () => value ignored which key was requested, so a typo'd env var name in config.ts would still pass every test. Mock by key instead. Co-Authored-By: Claude Sonnet 5 --- .../app/src/__tests__/config.instanceLabel.emoji.test.ts | 5 ++++- packages/app/src/__tests__/config.instanceLabel.test.ts | 5 ++++- .../src/__tests__/config.instanceLabel.whitespace.test.ts | 5 ++++- .../__tests__/config.instanceTitleSuffix.no-label.test.ts | 5 ++++- .../app/src/__tests__/config.instanceTitleSuffix.test.ts | 5 ++++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/app/src/__tests__/config.instanceLabel.emoji.test.ts b/packages/app/src/__tests__/config.instanceLabel.emoji.test.ts index b04bde33c8..7131f979b4 100644 --- a/packages/app/src/__tests__/config.instanceLabel.emoji.test.ts +++ b/packages/app/src/__tests__/config.instanceLabel.emoji.test.ts @@ -1,4 +1,7 @@ -jest.mock('next-runtime-env', () => ({ env: () => ' prod-U😀 ' })); +jest.mock('next-runtime-env', () => ({ + env: (key: string) => + key === 'NEXT_PUBLIC_INSTANCE_LABEL' ? ' prod-U😀 ' : undefined, +})); import { INSTANCE_LABEL } from '@/config'; diff --git a/packages/app/src/__tests__/config.instanceLabel.test.ts b/packages/app/src/__tests__/config.instanceLabel.test.ts index 830b491ec2..e0c8b69cdc 100644 --- a/packages/app/src/__tests__/config.instanceLabel.test.ts +++ b/packages/app/src/__tests__/config.instanceLabel.test.ts @@ -1,4 +1,7 @@ -jest.mock('next-runtime-env', () => ({ env: () => ' ExtraLongLabel ' })); +jest.mock('next-runtime-env', () => ({ + env: (key: string) => + key === 'NEXT_PUBLIC_INSTANCE_LABEL' ? ' ExtraLongLabel ' : undefined, +})); import { INSTANCE_LABEL } from '@/config'; diff --git a/packages/app/src/__tests__/config.instanceLabel.whitespace.test.ts b/packages/app/src/__tests__/config.instanceLabel.whitespace.test.ts index 6ee10cbe30..afa9478224 100644 --- a/packages/app/src/__tests__/config.instanceLabel.whitespace.test.ts +++ b/packages/app/src/__tests__/config.instanceLabel.whitespace.test.ts @@ -1,4 +1,7 @@ -jest.mock('next-runtime-env', () => ({ env: () => 'EU West' })); +jest.mock('next-runtime-env', () => ({ + env: (key: string) => + key === 'NEXT_PUBLIC_INSTANCE_LABEL' ? 'EU West' : undefined, +})); import { INSTANCE_LABEL } from '@/config'; diff --git a/packages/app/src/__tests__/config.instanceTitleSuffix.no-label.test.ts b/packages/app/src/__tests__/config.instanceTitleSuffix.no-label.test.ts index 7e24215b02..89994228f5 100644 --- a/packages/app/src/__tests__/config.instanceTitleSuffix.no-label.test.ts +++ b/packages/app/src/__tests__/config.instanceTitleSuffix.no-label.test.ts @@ -1,4 +1,7 @@ -jest.mock('next-runtime-env', () => ({ env: () => undefined })); +jest.mock('next-runtime-env', () => ({ + env: (key: string) => + key === 'NEXT_PUBLIC_INSTANCE_LABEL' ? undefined : 'unexpected', +})); import { INSTANCE_TITLE_SUFFIX } from '@/config'; diff --git a/packages/app/src/__tests__/config.instanceTitleSuffix.test.ts b/packages/app/src/__tests__/config.instanceTitleSuffix.test.ts index c46f8d3fea..17dfc176c9 100644 --- a/packages/app/src/__tests__/config.instanceTitleSuffix.test.ts +++ b/packages/app/src/__tests__/config.instanceTitleSuffix.test.ts @@ -1,4 +1,7 @@ -jest.mock('next-runtime-env', () => ({ env: () => 'UK' })); +jest.mock('next-runtime-env', () => ({ + env: (key: string) => + key === 'NEXT_PUBLIC_INSTANCE_LABEL' ? 'UK' : undefined, +})); import { INSTANCE_TITLE_SUFFIX } from '@/config'; From 43dbb158a2f2f1dcf3961d7406a1261b864ba890 Mon Sep 17 00:00:00 2001 From: arj22 Date: Tue, 6 Oct 2026 14:31:19 -0500 Subject: [PATCH 17/20] Fix stylelint: blank line before comment in AppNav.module.scss Co-Authored-By: Claude Sonnet 5 --- packages/app/src/components/AppNav/AppNav.module.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/app/src/components/AppNav/AppNav.module.scss b/packages/app/src/components/AppNav/AppNav.module.scss index 39c583510d..80415250fb 100644 --- a/packages/app/src/components/AppNav/AppNav.module.scss +++ b/packages/app/src/components/AppNav/AppNav.module.scss @@ -109,6 +109,7 @@ $transition-slow: 0.2s ease; align-items: center; justify-content: center; color: var(--color-text); + // Shrinkable (not growable) so a long label can still ellipsis when the // sidebar is narrow, without stretching this link to fill the empty // header space next to it (that space shouldn't be part of the link). From e542aba442971190d1bc5c868a3bb3fd8c9a15f1 Mon Sep 17 00:00:00 2001 From: arj22 Date: Tue, 6 Oct 2026 14:46:35 -0500 Subject: [PATCH 18/20] Add usePageTitle hook, consolidate page composition Replaces the repeated `${page} - ${brandName}${INSTANCE_TITLE_SUFFIX}` pattern across all page-title call sites with usePageTitle(page), per Brandon's review suggestion. Standardizes the few call sites that used an en dash or brand-first ordering (including login/register) to match. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --- packages/app/pages/_app.tsx | 16 ++++++++-------- packages/app/src/AlertDetailPage.tsx | 10 ++++++---- packages/app/src/AlertsPage.tsx | 7 +++---- packages/app/src/AuthPage.tsx | 4 ++-- packages/app/src/ClickhousePage.tsx | 7 +++---- packages/app/src/DBChartPage.tsx | 8 ++++---- packages/app/src/DBDashboardImportPage.tsx | 8 +++----- packages/app/src/DBDashboardPage.tsx | 7 +++---- packages/app/src/DBSearchPage.tsx | 10 ++++++---- packages/app/src/DBServiceMapPage.tsx | 10 +++++----- packages/app/src/JoinTeamPage.tsx | 8 +++----- packages/app/src/KubernetesDashboardPage.tsx | 7 +++---- .../ServicesDashboardPage.tsx | 8 ++++---- .../__tests__/ServicesDashboardPage.test.tsx | 1 + packages/app/src/SessionsPage.tsx | 7 +++---- packages/app/src/TeamPage.tsx | 8 ++++---- .../__tests__/DBSearchPage.directTrace.test.tsx | 1 + .../Dashboards/DashboardTemplatesPage.tsx | 7 +++---- .../components/Dashboards/DashboardsListPage.tsx | 8 ++++---- .../__tests__/DashboardsListPage.test.tsx | 1 + .../SavedSearches/SavedSearchesListPage.tsx | 7 +++---- .../app/src/llm/dashboard/LLMDashboardPage.tsx | 7 +++---- packages/app/src/theme/ThemeProvider.tsx | 13 +++++++++++++ 23 files changed, 89 insertions(+), 81 deletions(-) diff --git a/packages/app/pages/_app.tsx b/packages/app/pages/_app.tsx index 272f3f5a99..fb64f6fd68 100644 --- a/packages/app/pages/_app.tsx +++ b/packages/app/pages/_app.tsx @@ -15,11 +15,7 @@ import { import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; import { DynamicFavicon } from '@/components/DynamicFavicon'; -import { - INSTANCE_TITLE_SUFFIX, - IS_LOCAL_MODE, - parseResourceAttributes, -} from '@/config'; +import { IS_LOCAL_MODE, parseResourceAttributes } from '@/config'; import { DEFAULT_FONT_VAR, FONT_VAR_MAP, @@ -27,7 +23,11 @@ import { } from '@/config/fonts'; import { ibmPlexMono, inter, roboto, robotoMono } from '@/fonts'; import { fetchServerVersion, installHdxDebug } from '@/hdxDebug'; -import { AppThemeProvider, useAppTheme } from '@/theme/ThemeProvider'; +import { + AppThemeProvider, + useAppTheme, + usePageTitle, +} from '@/theme/ThemeProvider'; import { ThemeWrapper } from '@/ThemeWrapper'; import { NextApiConfigResponseData } from '@/types'; import { ConfirmProvider } from '@/useConfirm'; @@ -74,11 +74,11 @@ type AppPropsWithLayout = AppProps & { // Component that renders Head content requiring user preferences // Must be rendered inside AppThemeProvider to avoid hydration mismatch function AppHeadContent() { - const { theme } = useAppTheme(); + const title = usePageTitle(); return ( <Head> - <title>{`${theme.displayName}${INSTANCE_TITLE_SUFFIX}`} + {title} diff --git a/packages/app/src/AlertDetailPage.tsx b/packages/app/src/AlertDetailPage.tsx index eafcbbfe5d..841000c604 100644 --- a/packages/app/src/AlertDetailPage.tsx +++ b/packages/app/src/AlertDetailPage.tsx @@ -27,10 +27,10 @@ import { AlertStateBadge } from '@/components/alerts/AlertStateBadge'; import EmptyState from '@/components/EmptyState'; import { PageHeader } from '@/components/PageHeader'; import { TimePicker } from '@/components/TimePicker'; -import { INSTANCE_TITLE_SUFFIX, IS_ALERT_DETAILS_ENABLED } from '@/config'; +import { IS_ALERT_DETAILS_ENABLED } from '@/config'; import { getAlertSourceLabel, getAlertSourceUrl } from '@/utils/alerts'; -import { useBrandDisplayName } from './theme/ThemeProvider'; +import { usePageTitle } from './theme/ThemeProvider'; import api from './api'; import { withAppNavForSurface } from './layout'; import { useDefaultTimeRange, useNewTimeQuery } from './timeQuery'; @@ -223,7 +223,6 @@ function AlertDetailBody({ alert }: { alert: AlertsPageItem }) { } export default function AlertDetailPage() { - const brandName = useBrandDisplayName(); const router = useRouter(); const alertId = typeof router.query.alertId === 'string' ? router.query.alertId : undefined; @@ -238,6 +237,9 @@ export default function AlertDetailPage() { const { data, isLoading, isError } = api.useAlert(alertId); const alert = data?.data; + const title = usePageTitle( + alert ? `${alert.displayName} - Alerts` : 'Alerts', + ); if (!IS_ALERT_DETAILS_ENABLED) { return null; @@ -249,7 +251,7 @@ export default function AlertDetailPage() { style={{ display: 'flex', flexDirection: 'column', height: '100%' }} > - {`${alert ? `${alert.displayName} - Alerts` : 'Alerts'} - ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title} {isLoading && ( diff --git a/packages/app/src/AlertsPage.tsx b/packages/app/src/AlertsPage.tsx index 838060b44e..2c3c2d3387 100644 --- a/packages/app/src/AlertsPage.tsx +++ b/packages/app/src/AlertsPage.tsx @@ -19,17 +19,16 @@ import { AlertCardList } from '@/components/alerts/AlertCardList'; import { AlertsFilterBar } from '@/components/alerts/AlertsFilterBar'; import EmptyState from '@/components/EmptyState'; import { PageHeader } from '@/components/PageHeader'; -import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { ALERT_STATE_FILTER_OPTIONS } from '@/utils/alerts'; -import { useBrandDisplayName } from './theme/ThemeProvider'; +import { usePageTitle } from './theme/ThemeProvider'; import api from './api'; import { withAppNav } from './layout'; const SEARCH_DEBOUNCE_MS = 300; export default function AlertsPage() { - const brandName = useBrandDisplayName(); + const title = usePageTitle('Alerts'); const mounted = useMounted(); const [search, setSearch] = useQueryState('search'); @@ -115,7 +114,7 @@ export default function AlertsPage() { style={{ display: 'flex', flexDirection: 'column', minHeight: '100%' }} > - {`Alerts - ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title}
{ // If an OSS user accidentally lands on /register after already creating a team diff --git a/packages/app/src/ClickhousePage.tsx b/packages/app/src/ClickhousePage.tsx index a5412233fb..d190d89867 100644 --- a/packages/app/src/ClickhousePage.tsx +++ b/packages/app/src/ClickhousePage.tsx @@ -36,7 +36,6 @@ import { ConnectionSelectControlled } from '@/components/ConnectionSelect'; import { DBTimeChart } from '@/components/DBTimeChart'; import { PageLayout } from '@/components/PageLayout'; import { TimePicker } from '@/components/TimePicker'; -import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { withAppNavForSurface } from '@/layout'; import { ChartCard } from './components/charts/ChartCard'; @@ -46,7 +45,7 @@ import { DBSqlRowTable } from './components/DBRowTable'; import DBTableChart from './components/DBTableChart'; import OnboardingModal from './components/OnboardingModal'; import { useDashboardRefresh } from './hooks/useDashboardRefresh'; -import { useBrandDisplayName } from './theme/ThemeProvider'; +import { usePageTitle } from './theme/ThemeProvider'; import { clickhouseSql } from './utils/codeMirror'; import { useConnections } from './connection'; import { useDefaultTimeRange, useNewTimeQuery } from './timeQuery'; @@ -492,7 +491,7 @@ const DEFAULT_INTERVAL = 'Past 1h'; function ClickhousePage() { const defaultTimeRange = useDefaultTimeRange(DEFAULT_INTERVAL); - const brandName = useBrandDisplayName(); + const title = usePageTitle('ClickHouse Dashboard'); const { colorScheme } = useMantineColorScheme(); const { data: connections } = useConnections(); const [_connection, setConnection] = useQueryState('connection'); @@ -645,7 +644,7 @@ function ClickhousePage() { content={ <> - {`ClickHouse Dashboard – ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title} - {`Chart Explorer - ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title} - {`Import Dashboard - ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title} diff --git a/packages/app/src/DBDashboardPage.tsx b/packages/app/src/DBDashboardPage.tsx index ffe55c6b52..41e19d39b9 100644 --- a/packages/app/src/DBDashboardPage.tsx +++ b/packages/app/src/DBDashboardPage.tsx @@ -153,7 +153,6 @@ import { parseTimeRangeInput, timeRangeInputToSeconds, } from '@/components/TimePicker/utils'; -import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { Dashboard, type Tile, @@ -189,7 +188,7 @@ import { Tags } from './components/Tags'; import useDashboardFilters from './hooks/useDashboardFilters'; import { useDashboardRefresh } from './hooks/useDashboardRefresh'; import useTileSelection from './hooks/useTileSelection'; -import { useBrandDisplayName } from './theme/ThemeProvider'; +import { usePageTitle } from './theme/ThemeProvider'; import { parseAsJsonEncoded, parseAsStringEncoded } from './utils/queryParsers'; import { buildDashboardReplaySearchUrl, @@ -1891,7 +1890,7 @@ function DBDashboardPage({ isFetching: isFetchingDashboard, isSetting: isSavingDashboard, } = dashboardProps; - const brandName = useBrandDisplayName(); + const title = usePageTitle(dashboard?.name ? dashboard.name : 'Dashboard'); const confirm = useConfirm(); const { userPreferences: { isUTC }, @@ -3227,7 +3226,7 @@ function DBDashboardPage({ const dashboardBody = ( <> - {`${dashboard?.name ? dashboard.name : 'Dashboard'} – ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title} {!isKioskMode && } {!isKioskMode && ( diff --git a/packages/app/src/DBSearchPage.tsx b/packages/app/src/DBSearchPage.tsx index 195492437e..e7a257d397 100644 --- a/packages/app/src/DBSearchPage.tsx +++ b/packages/app/src/DBSearchPage.tsx @@ -109,7 +109,7 @@ import { SourceSelectControlled } from '@/components/SourceSelect'; import { SQLInlineEditorControlled } from '@/components/SQLEditor/SQLInlineEditor'; import { Tags } from '@/components/Tags'; import { TimePicker } from '@/components/TimePicker'; -import { INSTANCE_TITLE_SUFFIX, IS_LOCAL_MODE } from '@/config'; +import { IS_LOCAL_MODE } from '@/config'; import { useAliasMapFromChartConfig } from '@/hooks/useChartConfig'; import { useExplainQuery } from '@/hooks/useExplainQuery'; import { useResolvedSourceParam } from '@/hooks/useResolvedSourceParam'; @@ -124,7 +124,7 @@ import { } from '@/savedSearch'; import { useSearchPageFilterState } from '@/searchFilters'; import { getEventBody, useSource, useSources } from '@/source'; -import { useAppTheme, useBrandDisplayName } from '@/theme/ThemeProvider'; +import { useAppTheme, usePageTitle } from '@/theme/ThemeProvider'; import { parseRelativeTimeQuery, useDefaultTimeRange, @@ -1038,7 +1038,6 @@ function DBSearchPageContent() { // Read again here, not passed down: this component re-renders from its own // query-state hooks without the wrapper, and must see the current path. const savedSearchId = getSavedSearchIdFromPath(); - const brandName = useBrandDisplayName(); const defaultTimeRange = useDefaultTimeRange('Past 15m'); const [rawSearchedConfig, setSearchedConfig] = useQueryStates(queryStateMap); @@ -1067,6 +1066,9 @@ function DBSearchPageContent() { enabled: savedSearchId != null, }, ); + const title = usePageTitle( + savedSearch ? `${savedSearch.name} Search` : 'Search', + ); const { data: sources } = useSources(); const [lastSelectedSourceId, setLastSelectedSourceId] = useLocalStorage( @@ -2215,7 +2217,7 @@ function DBSearchPageContent() { data-testid="search-page" > - {`${savedSearch ? `${savedSearch.name} Search` : 'Search'} - ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title} {!IS_LOCAL_MODE && isAlertModalOpen && ( ( <> - {`Service Map - ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title} ), - [brandName], + [title], ); const sourceSelect = source ? ( diff --git a/packages/app/src/JoinTeamPage.tsx b/packages/app/src/JoinTeamPage.tsx index 0fb3c86f02..ec4e4e3b4a 100644 --- a/packages/app/src/JoinTeamPage.tsx +++ b/packages/app/src/JoinTeamPage.tsx @@ -10,14 +10,12 @@ import { TextInput, } from '@mantine/core'; -import { INSTANCE_TITLE_SUFFIX } from '@/config'; - -import { useBrandDisplayName } from './theme/ThemeProvider'; +import { usePageTitle } from './theme/ThemeProvider'; import { PasswordCheck } from './PasswordCheck'; export default function JoinTeam() { const router = useRouter(); - const brandName = useBrandDisplayName(); + const title = usePageTitle('Join Team'); const { err, reason, token } = router.query; const [password, setPassword] = useState(''); @@ -33,7 +31,7 @@ export default function JoinTeam() { return (
- +
diff --git a/packages/app/src/KubernetesDashboardPage.tsx b/packages/app/src/KubernetesDashboardPage.tsx index 918af8c2e2..d4c64baca9 100644 --- a/packages/app/src/KubernetesDashboardPage.tsx +++ b/packages/app/src/KubernetesDashboardPage.tsx @@ -43,7 +43,6 @@ import { useVirtualizer } from '@tanstack/react-virtual'; import { PageLayout } from '@/components/PageLayout'; import { TimePicker } from '@/components/TimePicker'; -import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { useResolvedSourceParam } from '@/hooks/useResolvedSourceParam'; import { useVirtualList } from '@/hooks/useVirtualList'; @@ -59,7 +58,7 @@ import { SourceSelectControlled } from './components/SourceSelect'; import { useQueriedChartConfig } from './hooks/useChartConfig'; import { useDashboardRefresh } from './hooks/useDashboardRefresh'; import { useJsonColumns } from './hooks/useMetadata'; -import { useBrandDisplayName } from './theme/ThemeProvider'; +import { usePageTitle } from './theme/ThemeProvider'; import { convertV1ChartConfigToV2, K8S_CPU_PERCENTAGE_NUMBER_FORMAT, @@ -1050,7 +1049,7 @@ const DEFAULT_INTERVAL = 'Past 1h'; function KubernetesDashboardPage() { const defaultTimeRange = useDefaultTimeRange(DEFAULT_INTERVAL); - const brandName = useBrandDisplayName(); + const title = usePageTitle('Kubernetes Dashboard'); const { data: sources } = useSources(); const [_logSourceId, setLogSourceId] = useQueryState('logSource'); @@ -1379,7 +1378,7 @@ function KubernetesDashboardPage() { const dashboardBody = ( <> - {`Kubernetes Dashboard – ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title} {metricSource && logSource && ( diff --git a/packages/app/src/ServicesDashboardPage/ServicesDashboardPage.tsx b/packages/app/src/ServicesDashboardPage/ServicesDashboardPage.tsx index 896ba5b918..d703020653 100644 --- a/packages/app/src/ServicesDashboardPage/ServicesDashboardPage.tsx +++ b/packages/app/src/ServicesDashboardPage/ServicesDashboardPage.tsx @@ -48,7 +48,7 @@ import ServiceDashboardDbQuerySidePanel from '@/components/ServiceDashboardDbQue import ServiceDashboardEndpointSidePanel from '@/components/ServiceDashboardEndpointSidePanel'; import { SourceSelectControlled } from '@/components/SourceSelect'; import { TimePicker } from '@/components/TimePicker'; -import { INSTANCE_TITLE_SUFFIX, IS_LOCAL_MODE } from '@/config'; +import { IS_LOCAL_MODE } from '@/config'; import DashboardFilters from '@/DashboardFilters'; import { useQueriedChartConfig } from '@/hooks/useChartConfig'; import { useDashboardRefresh } from '@/hooks/useDashboardRefresh'; @@ -57,7 +57,7 @@ import { useResolvedSourceParam } from '@/hooks/useResolvedSourceParam'; import { withAppNavForSurface } from '@/layout'; import { useServiceDashboardExpressions } from '@/serviceDashboard'; import { useSource, useSources } from '@/source'; -import { useBrandDisplayName } from '@/theme/ThemeProvider'; +import { usePageTitle } from '@/theme/ThemeProvider'; import { useDefaultTimeRange, useNewTimeQuery } from '@/timeQuery'; import DatabaseTab from './DatabaseTab'; @@ -166,7 +166,7 @@ const DEFAULT_INTERVAL = 'Past 1h'; function ServicesDashboardPage() { const defaultTimeRange = useDefaultTimeRange(DEFAULT_INTERVAL); - const brandName = useBrandDisplayName(); + const title = usePageTitle('Services Dashboard'); const [tab, setTab] = useQueryState( 'tab', parseAsStringEnum(['http', 'database', 'errors']).withDefault( @@ -313,7 +313,7 @@ function ServicesDashboardPage() { return ( - {`Services Dashboard – ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title} diff --git a/packages/app/src/ServicesDashboardPage/__tests__/ServicesDashboardPage.test.tsx b/packages/app/src/ServicesDashboardPage/__tests__/ServicesDashboardPage.test.tsx index 7f4d58301b..76f26b5a05 100644 --- a/packages/app/src/ServicesDashboardPage/__tests__/ServicesDashboardPage.test.tsx +++ b/packages/app/src/ServicesDashboardPage/__tests__/ServicesDashboardPage.test.tsx @@ -165,6 +165,7 @@ jest.mock('@/layout', () => ({ jest.mock('@/theme/ThemeProvider', () => ({ __esModule: true, useBrandDisplayName: () => 'HyperDX', + usePageTitle: (page?: string) => (page ? `${page} - HyperDX` : 'HyperDX'), })); import ServicesDashboardPage from '@/ServicesDashboardPage'; diff --git a/packages/app/src/SessionsPage.tsx b/packages/app/src/SessionsPage.tsx index 5a6ef6c0e9..51c6be1ff5 100644 --- a/packages/app/src/SessionsPage.tsx +++ b/packages/app/src/SessionsPage.tsx @@ -45,7 +45,6 @@ import { PageHeader } from '@/components/PageHeader'; import { PageLayout } from '@/components/PageLayout'; import { SourceSelectControlled } from '@/components/SourceSelect'; import { TimePicker } from '@/components/TimePicker'; -import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { useDashboardRefresh } from '@/hooks/useDashboardRefresh'; import { useResolvedSourceParam } from '@/hooks/useResolvedSourceParam'; import { useDefaultTimeRange, useNewTimeQuery } from '@/timeQuery'; @@ -54,7 +53,7 @@ import OnboardingModal from './components/OnboardingModal'; import SearchWhereInput, { getStoredLanguage, } from './components/SearchInput/SearchWhereInput'; -import { useBrandDisplayName } from './theme/ThemeProvider'; +import { useBrandDisplayName, usePageTitle } from './theme/ThemeProvider'; import { withAppNavForSurface } from './layout'; import { Session, useSessions } from './sessions'; import SessionSidePanel from './SessionSidePanel'; @@ -241,7 +240,7 @@ const DEFAULT_INTERVAL = 'Past 1h'; function SessionsPage() { const defaultTimeRange = useDefaultTimeRange(DEFAULT_INTERVAL); - const brandName = useBrandDisplayName(); + const title = usePageTitle('Client Sessions'); const [appliedConfig, setAppliedConfig] = useQueryStates(appliedConfigMap); // `?sessionSource=` accepts a source name as well as a source ID. The form // holds the resolved ID, so nothing downstream ever sees a name. @@ -398,7 +397,7 @@ function SessionsPage() { return ( <> - {`Client Sessions - ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title} {selectedSession != null && diff --git a/packages/app/src/TeamPage.tsx b/packages/app/src/TeamPage.tsx index 23f8ec1362..b536fe5290 100644 --- a/packages/app/src/TeamPage.tsx +++ b/packages/app/src/TeamPage.tsx @@ -34,9 +34,9 @@ import SecurityPoliciesSection from './components/TeamSettings/SecurityPoliciesS import SourcesSection from './components/TeamSettings/SourcesSection'; import TeamMembersSection from './components/TeamSettings/TeamMembersSection'; import TeamQueryConfigSection from './components/TeamSettings/TeamQueryConfigSection'; -import { useBrandDisplayName } from './theme/ThemeProvider'; +import { usePageTitle } from './theme/ThemeProvider'; import api from './api'; -import { INSTANCE_TITLE_SUFFIX, IS_IAC_EXPORT_ENABLED } from './config'; +import { IS_IAC_EXPORT_ENABLED } from './config'; import { APP_CONTENT_SCROLL_CONTAINER_ID, withAppNav } from './layout'; type TeamTab = { @@ -73,7 +73,7 @@ function TeamTabContent({ } export default function TeamPage() { - const brandName = useBrandDisplayName(); + const title = usePageTitle('My Team'); const router = useRouter(); const { data: team, refetch: refetchTeam, isLoading } = api.useTeam(); const setTeamName = api.useSetTeamName(); @@ -269,7 +269,7 @@ export default function TeamPage() { return (
- {`My Team - ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title}
diff --git a/packages/app/src/__tests__/DBSearchPage.directTrace.test.tsx b/packages/app/src/__tests__/DBSearchPage.directTrace.test.tsx index a6fe0278b6..fdee8e270e 100644 --- a/packages/app/src/__tests__/DBSearchPage.directTrace.test.tsx +++ b/packages/app/src/__tests__/DBSearchPage.directTrace.test.tsx @@ -132,6 +132,7 @@ jest.mock('@/hooks/useExplainQuery', () => ({ jest.mock('@/theme/ThemeProvider', () => ({ useAppTheme: () => ({ themeName: 'hyperdx' }), useBrandDisplayName: () => 'HyperDX', + usePageTitle: (page?: string) => (page ? `${page} - HyperDX` : 'HyperDX'), })); jest.mock('../hooks/useMetadata', () => ({ diff --git a/packages/app/src/components/Dashboards/DashboardTemplatesPage.tsx b/packages/app/src/components/Dashboards/DashboardTemplatesPage.tsx index 1591f38519..2fe6470909 100644 --- a/packages/app/src/components/Dashboards/DashboardTemplatesPage.tsx +++ b/packages/app/src/components/Dashboards/DashboardTemplatesPage.tsx @@ -13,13 +13,12 @@ import { } from '@mantine/core'; import { IconUpload } from '@tabler/icons-react'; -import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { DASHBOARD_TEMPLATES } from '@/dashboardTemplates'; import { withAppNav } from '@/layout'; -import { useBrandDisplayName } from '@/theme/ThemeProvider'; +import { usePageTitle } from '@/theme/ThemeProvider'; export default function DashboardTemplatesPage() { - const brandName = useBrandDisplayName(); + const title = usePageTitle('Dashboard Templates'); const templatesByTag = useMemo(() => { const groups = new Map(); @@ -45,7 +44,7 @@ export default function DashboardTemplatesPage() { return (
- {`Dashboard Templates - ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title} diff --git a/packages/app/src/components/Dashboards/DashboardsListPage.tsx b/packages/app/src/components/Dashboards/DashboardsListPage.tsx index 47004aa99f..10299cd622 100644 --- a/packages/app/src/components/Dashboards/DashboardsListPage.tsx +++ b/packages/app/src/components/Dashboards/DashboardsListPage.tsx @@ -46,7 +46,7 @@ import { FavoriteButton } from '@/components/FavoriteButton'; import { ListingCard } from '@/components/ListingCard'; import { ListingRow } from '@/components/ListingListRow'; import { PageHeader } from '@/components/PageHeader'; -import { INSTANCE_TITLE_SUFFIX, IS_K8S_DASHBOARD_ENABLED } from '@/config'; +import { IS_K8S_DASHBOARD_ENABLED } from '@/config'; import { type Dashboard, useCreateDashboard, @@ -55,7 +55,7 @@ import { } from '@/dashboard'; import { useFavorites } from '@/favorites'; import { withAppNav } from '@/layout'; -import { useBrandDisplayName } from '@/theme/ThemeProvider'; +import { usePageTitle } from '@/theme/ThemeProvider'; import { useConfirm } from '@/useConfirm'; function getDashboardAlerts(tiles: Dashboard['tiles']) { @@ -97,7 +97,7 @@ const PRESET_DASHBOARDS = [ ]; export default function DashboardsListPage() { - const brandName = useBrandDisplayName(); + const title = usePageTitle('Dashboards'); const { data: dashboards, isLoading, isError } = useDashboards(); const { data: me, isPending: isMePending } = api.useMe(); const confirm = useConfirm(); @@ -218,7 +218,7 @@ export default function DashboardsListPage() { style={{ display: 'flex', flexDirection: 'column', minHeight: '100%' }} > - {`Dashboards - ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title} ({ })); jest.mock('@/theme/ThemeProvider', () => ({ useBrandDisplayName: () => 'HyperDX', + usePageTitle: (page?: string) => (page ? `${page} - HyperDX` : 'HyperDX'), })); jest.mock('@/useConfirm', () => ({ useConfirm: () => jest.fn(), diff --git a/packages/app/src/components/SavedSearches/SavedSearchesListPage.tsx b/packages/app/src/components/SavedSearches/SavedSearchesListPage.tsx index cbeeefbf3c..a97b062170 100644 --- a/packages/app/src/components/SavedSearches/SavedSearchesListPage.tsx +++ b/packages/app/src/components/SavedSearches/SavedSearchesListPage.tsx @@ -30,16 +30,15 @@ import { FavoriteButton } from '@/components/FavoriteButton'; import { ListingCard } from '@/components/ListingCard'; import { ListingRow } from '@/components/ListingListRow'; import { PageHeader } from '@/components/PageHeader'; -import { INSTANCE_TITLE_SUFFIX } from '@/config'; import { useFavorites } from '@/favorites'; import { withAppNav } from '@/layout'; import { useDeleteSavedSearch, useSavedSearches } from '@/savedSearch'; -import { useBrandDisplayName } from '@/theme/ThemeProvider'; +import { usePageTitle } from '@/theme/ThemeProvider'; import { useConfirm } from '@/useConfirm'; import { groupByTags } from '@/utils/groupByTags'; export default function SavedSearchesListPage() { - const brandName = useBrandDisplayName(); + const title = usePageTitle('Saved Searches'); const { data: savedSearches, isLoading, isError } = useSavedSearches(); const confirm = useConfirm(); const deleteSavedSearch = useDeleteSavedSearch(); @@ -127,7 +126,7 @@ export default function SavedSearchesListPage() { style={{ display: 'flex', flexDirection: 'column', height: '100%' }} > - {`Saved Searches - ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title} - {`LLM Dashboard – ${brandName}${INSTANCE_TITLE_SUFFIX}`} + {title} diff --git a/packages/app/src/theme/ThemeProvider.tsx b/packages/app/src/theme/ThemeProvider.tsx index 071601dfa9..def5bf6ed3 100644 --- a/packages/app/src/theme/ThemeProvider.tsx +++ b/packages/app/src/theme/ThemeProvider.tsx @@ -8,6 +8,8 @@ import React, { useState, } from 'react'; +import { INSTANCE_TITLE_SUFFIX } from '@/config'; + import { DEFAULT_THEME, getDevThemeName, @@ -241,3 +243,14 @@ export function useBrandDisplayName(): string { const { theme } = useAppTheme(); return theme.displayName; } + +/** + * Hook to build a ``/`<NextSeo title>` value: brand name plus the + * configured instance label, with an optional page name prepended. + * e.g. usePageTitle('Search') => "Search - HyperDX - USA" + */ +export function usePageTitle(page?: string): string { + const brandName = useBrandDisplayName(); + const brandTitle = `${brandName}${INSTANCE_TITLE_SUFFIX}`; + return page ? `${page} - ${brandTitle}` : brandTitle; +} From 8caf5ba0e2f1f921a619116d352e71af55a39990 Mon Sep 17 00:00:00 2001 From: arj22 <anudeep@nightfall.ai> Date: Tue, 6 Oct 2026 14:52:12 -0500 Subject: [PATCH 19/20] Fix usePageTitle doc example, add unit test coverage Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --- packages/app/src/theme/ThemeProvider.tsx | 2 +- .../theme/__tests__/ThemeProvider.test.tsx | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/app/src/theme/ThemeProvider.tsx b/packages/app/src/theme/ThemeProvider.tsx index def5bf6ed3..4ba8c23528 100644 --- a/packages/app/src/theme/ThemeProvider.tsx +++ b/packages/app/src/theme/ThemeProvider.tsx @@ -247,7 +247,7 @@ export function useBrandDisplayName(): string { /** * Hook to build a `<title>`/`<NextSeo title>` value: brand name plus the * configured instance label, with an optional page name prepended. - * e.g. usePageTitle('Search') => "Search - HyperDX - USA" + * e.g. usePageTitle('Search') => "Search - HyperDX USA" */ export function usePageTitle(page?: string): string { const brandName = useBrandDisplayName(); diff --git a/packages/app/src/theme/__tests__/ThemeProvider.test.tsx b/packages/app/src/theme/__tests__/ThemeProvider.test.tsx index 8f213d0829..008239a8f3 100644 --- a/packages/app/src/theme/__tests__/ThemeProvider.test.tsx +++ b/packages/app/src/theme/__tests__/ThemeProvider.test.tsx @@ -17,10 +17,13 @@ import { AppThemeProvider, useAppTheme, useLogomark, + usePageTitle, useThemeName, useWordmark, } from '@/theme/ThemeProvider'; +jest.mock('@/config', () => ({ INSTANCE_TITLE_SUFFIX: ' UK' })); + // Mock localStorage let localStorageMock: jest.Mocked<Storage>; @@ -144,6 +147,24 @@ describe('ThemeProvider', () => { }); }); + describe('usePageTitle', () => { + const wrapper = ({ children }: { children: React.ReactNode }) => ( + <AppThemeProvider>{children}</AppThemeProvider> + ); + + it('appends the brand name and instance suffix with no page name', () => { + const { result } = renderHook(() => usePageTitle(), { wrapper }); + + expect(result.current).toBe('HyperDX UK'); + }); + + it('prepends the page name when given one', () => { + const { result } = renderHook(() => usePageTitle('Search'), { wrapper }); + + expect(result.current).toBe('Search - HyperDX UK'); + }); + }); + describe('useThemeName', () => { it('should return current theme name', () => { const wrapper = ({ children }: { children: React.ReactNode }) => ( From 881cd36b2d6944b4a6d9b24bfc97a164273dc9eb Mon Sep 17 00:00:00 2001 From: arj22 <anudeep@nightfall.ai> Date: Tue, 6 Oct 2026 14:53:42 -0500 Subject: [PATCH 20/20] Fix e2e dashboard-rename title assertion for new separator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit usePageTitle composes with " - ", not the old " – " used before the DBDashboardPage title-string refactor. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --- packages/app/tests/e2e/page-objects/DashboardPage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/tests/e2e/page-objects/DashboardPage.ts b/packages/app/tests/e2e/page-objects/DashboardPage.ts index 419aaf3260..35bca0b325 100644 --- a/packages/app/tests/e2e/page-objects/DashboardPage.ts +++ b/packages/app/tests/e2e/page-objects/DashboardPage.ts @@ -275,7 +275,7 @@ export class DashboardPage { // The document title comes from the saved dashboard, so it only changes // once the rename has persisted. const escaped = newName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); - await expect(this.page).toHaveTitle(new RegExp(`^${escaped} – `), { + await expect(this.page).toHaveTitle(new RegExp(`^${escaped} - `), { timeout: 10000, }); }