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(frontend): render login before feature flags arrive (#118462)

Paul D'Ambra4711e8517ab7
diff --git a/frontend/src/scenes/appLogic.test.ts b/frontend/src/scenes/appLogic.test.ts
new file mode 100644
index 000000000000..f2d70b8fc4eb
--- /dev/null
+++ b/frontend/src/scenes/appLogic.test.ts
@@ -0,0 +1,70 @@
+import { MOCK_DEFAULT_USER } from 'lib/api.mock'
+
+import { router } from 'kea-router'
+
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { appLogic } from 'scenes/appLogic'
+import { userLogic } from 'scenes/userLogic'
+
+import preflightJson from '~/mocks/fixtures/_preflight.json'
+import { initKeaTests } from '~/test/init'
+import { AppContext, PreflightStatus } from '~/types'
+
+describe('appLogic', () => {
+ afterEach(() => {
+ window.POSTHOG_APP_CONTEXT = undefined
+ })
+
+ it.each([
+ { page: '/login', loggedIn: false, flagsArrived: false, timedOut: false, showApp: true },
+ { page: '/signup', loggedIn: false, flagsArrived: false, timedOut: false, showApp: false },
+ { page: '/signup', loggedIn: false, flagsArrived: true, timedOut: false, showApp: true },
+ { page: '/signup', loggedIn: false, flagsArrived: false, timedOut: true, showApp: true },
+ { page: '/login', loggedIn: true, flagsArrived: false, timedOut: false, showApp: false },
+ { page: '/login', loggedIn: true, flagsArrived: true, timedOut: false, showApp: true },
+ {
+ fromPage: '/login',
+ page: '/signup',
+ loggedIn: false,
+ flagsArrived: false,
+ timedOut: false,
+ showApp: false,
+ },
+ {
+ fromPage: '/signup',
+ page: '/login',
+ loggedIn: false,
+ flagsArrived: false,
+ timedOut: false,
+ showApp: true,
+ },
+ ])(
+ '$page loggedIn=$loggedIn flagsArrived=$flagsArrived timedOut=$timedOut shows=$showApp',
+ ({ page, fromPage, loggedIn, flagsArrived, timedOut, showApp }) => {
+ window.POSTHOG_APP_CONTEXT = {
+ current_user: loggedIn ? MOCK_DEFAULT_USER : null,
+ preflight: {
+ ...preflightJson,
+ slack_service: { available: false },
+ data_warehouse_integrations: { hubspot: {}, salesforce: {} },
+ wizard_cloud_run_available: false,
+ } as PreflightStatus,
+ } as AppContext
+ initKeaTests()
+ router.actions.push(fromPage ?? page)
+ userLogic.mount()
+ appLogic.mount()
+ if (fromPage) {
+ router.actions.push(page)
+ }
+ if (flagsArrived) {
+ featureFlagLogic.actions.setFeatureFlags([], {})
+ }
+ if (timedOut) {
+ appLogic.actions.ignoreFeatureFlags()
+ }
+
+ expect(!!appLogic.values.showApp).toBe(showApp)
+ }
+ )
+})
diff --git a/frontend/src/scenes/appLogic.tsx b/frontend/src/scenes/appLogic.tsx
index 5b511be4aa47..9ee3cfb6dc69 100644
--- a/frontend/src/scenes/appLogic.tsx
+++ b/frontend/src/scenes/appLogic.tsx
@@ -1,5 +1,5 @@
import { MakeLogicType, actions, connect, events, kea, path, reducers, selectors } from 'kea'
-import { urlToAction } from 'kea-router'
+import { router, urlToAction } from 'kea-router'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { organizationLogic } from 'scenes/organizationLogic'
@@ -12,6 +12,7 @@ import type { PreflightStatus } from '../types'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface appLogicValues {
featureFlagsTimedOut: boolean
+ isLoginPage: boolean
showApp: boolean | PreflightStatus | null
showingDelayedSpinner: boolean
showingDevTools: boolean
@@ -33,13 +34,15 @@ export interface appLogicActions {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface appLogicMeta {
__keaTypeGenInternalSelectorTypes: {
+ isLoginPage: (location: { hash: string; pathname: string; search: string }) => boolean
showApp: (
userLoading: boolean,
user: null | import('../types').UserType,
receivedFeatureFlags: boolean,
featureFlagsTimedOut: boolean,
preflightLoading: boolean,
- preflight: PreflightStatus | null
+ preflight: PreflightStatus | null,
+ isLoginPage: boolean
) => boolean | PreflightStatus | null
}
}
@@ -61,6 +64,7 @@ export const appLogic = kea<appLogicType>([
showingDevTools: [false, { showDevTools: () => true }],
}),
selectors({
+ isLoginPage: [() => [router.selectors.location], ({ pathname }): boolean => pathname === '/login'],
showApp: [
(s) => [
userLogic.selectors.userLoading,
@@ -69,6 +73,7 @@ export const appLogic = kea<appLogicType>([
s.featureFlagsTimedOut,
preflightLogic.selectors.preflightLoading,
preflightLogic.selectors.preflight,
+ s.isLoginPage,
],
(
userLoading: boolean,
@@ -76,13 +81,12 @@ export const appLogic = kea<appLogicType>([
receivedFeatureFlags: boolean,
featureFlagsTimedOut: boolean,
preflightLoading: boolean,
- preflight: null | import('../types').PreflightStatus
+ preflight: null | import('../types').PreflightStatus,
+ isLoginPage: boolean
) => {
- return (
- (!userLoading || user) &&
- (receivedFeatureFlags || featureFlagsTimedOut) &&
- (!preflightLoading || preflight)
- )
+ // Signup reads maintenance redirect flags when it mounts, so only login can bypass this wait.
+ const flagsReady = receivedFeatureFlags || featureFlagsTimedOut || (!user && isLoginPage)
+ return (!userLoading || user) && flagsReady && (!preflightLoading || preflight)
},
],
}),