Skip to content

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

fix(flags): don't redirect the staff tools page to a project url (#69146)

Phil Haack59164ad32cb1
diff --git a/frontend/src/lib/utils/kea-router.test.ts b/frontend/src/lib/utils/kea-router.test.ts
index f816cdf6af0c..c2e993478b44 100644
--- a/frontend/src/lib/utils/kea-router.test.ts
+++ b/frontend/src/lib/utils/kea-router.test.ts
@@ -13,6 +13,22 @@ describe('router-utils', () => {
const altered = addProjectIdIfMissing('/project/phc_gE7SWBNBgFbA4eQ154KPXebyB8KyLJuypR8jg1DSo9Z/replay', 123)
expect(altered).toEqual('/project/phc_gE7SWBNBgFbA4eQ154KPXebyB8KyLJuypR8jg1DSo9Z/replay')
})
+ it('does not redirect the instance-level feature flags staff tools URL to a project URL', () => {
+ const altered = addProjectIdIfMissing('/feature_flags/staff', 123)
+ expect(altered).toEqual('/feature_flags/staff')
+ })
+ it('does not redirect the staff tools URL when it carries a query string', () => {
+ const altered = addProjectIdIfMissing('/feature_flags/staff?team_id=456', 123)
+ expect(altered).toEqual('/feature_flags/staff?team_id=456')
+ })
+ it('does not redirect the staff tools URL when it carries a hash', () => {
+ const altered = addProjectIdIfMissing('/feature_flags/staff#cache', 123)
+ expect(altered).toEqual('/feature_flags/staff#cache')
+ })
+ it('still adds a project id to other feature flags URLs', () => {
+ const altered = addProjectIdIfMissing('/feature_flags/123', 123)
+ expect(altered).toEqual('/project/123/feature_flags/123')
+ })
describe('relative path normalization', () => {
it('normalizes ../ prefix to absolute path with project id', () => {
diff --git a/frontend/src/lib/utils/kea-router.ts b/frontend/src/lib/utils/kea-router.ts
index 3e6284575f79..0782d95288b2 100644
--- a/frontend/src/lib/utils/kea-router.ts
+++ b/frontend/src/lib/utils/kea-router.ts
@@ -20,10 +20,20 @@ const pathsWithoutProjectId = [
'render_query',
]
+// Instance-level pages that live under a product's own path prefix rather than
+// under `/instance/*`, so they need an exact (rather than first-segment) exemption.
+const exactPathsWithoutProjectId = ['/feature_flags/staff']
+
const projectIdentifierInUrlRegex = /^\/project\/(\d+|phc_)/
function isPathWithoutProjectId(path: string): boolean {
- const firstPart = path.split('/')[1]
+ const pathname = path.split(/[?#]/)[0]
+ if (
+ exactPathsWithoutProjectId.some((exactPath) => pathname === exactPath || pathname.startsWith(exactPath + '/'))
+ ) {
+ return true
+ }
+ const firstPart = pathname.split('/')[1]
return pathsWithoutProjectId.includes(firstPart)
}