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): defer heavy edit form and fix scene title action overlap (#67532)

posthog[bot]ce5a82cd927e
diff --git a/frontend/src/layout/scenes/components/SceneTitleSection.tsx b/frontend/src/layout/scenes/components/SceneTitleSection.tsx
index f14e3e91f4b7..0b49f8455ebe 100644
--- a/frontend/src/layout/scenes/components/SceneTitleSection.tsx
+++ b/frontend/src/layout/scenes/components/SceneTitleSection.tsx
@@ -382,7 +382,10 @@ export function SceneTitleSection({
{effectiveActions && (
<div
className={cn(
- 'flex gap-1.5 justify-end items-end @2xl/main-content:items-start ml-4 @max-2xl:order-first',
+ // relative z-30 keeps the corner actions above the focus-elevated name/description
+ // editors (z-20) so focusing an edit field can never overlap and swallow their clicks,
+ // notably on mobile where this container reflows into the corner via order-first.
+ 'relative z-30 flex gap-1.5 justify-end items-end @2xl/main-content:items-start ml-4 @max-2xl:order-first',
'gap-1 self-start @max-2xl:self-end flex-wrap'
)}
>
@@ -565,7 +568,7 @@ export function SceneName({
<ButtonPrimitive
className={cn(
buttonPrimitiveVariants({ size: 'fit', className: textClasses }),
- 'flex text-left [&_.LemonIcon]:size-4 focus-visible:z-50'
+ 'flex text-left [&_.LemonIcon]:size-4 focus-visible:z-20'
)}
onClick={() => {
if (!isGeneratingMetadata) {
@@ -593,7 +596,7 @@ export function SceneName({
if (isLoading) {
return (
- <div className="w-full flex-1 focus-within:z-50">
+ <div className="w-full flex-1 focus-within:z-20">
<WrappingLoadingSkeleton fullWidth>{Element}</WrappingLoadingSkeleton>
</div>
)
@@ -737,7 +740,7 @@ function SceneDescription({
}
}}
disabled={isGeneratingMetadata}
- className="flex text-start px-[var(--button-padding-x-sm)] py-[var(--button-padding-y-base)] [&_.LemonIcon]:size-4 focus-visible:z-50"
+ className="flex text-start px-[var(--button-padding-x-sm)] py-[var(--button-padding-y-base)] [&_.LemonIcon]:size-4 focus-visible:z-20"
autoHeight
size="base"
>
@@ -785,7 +788,7 @@ function SceneDescription({
}
return (
- <div className="scene-description relative focus-within:z-50">
+ <div className="scene-description relative focus-within:z-20">
<div className="-mx-[var(--button-padding-x-sm)] flex items-center gap-0">{Element}</div>
</div>
)
diff --git a/frontend/src/scenes/feature-flags/FeatureFlag.tsx b/frontend/src/scenes/feature-flags/FeatureFlag.tsx
index 41d688b9adab..26eddf9ce204 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlag.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlag.tsx
@@ -2,7 +2,7 @@ import './FeatureFlag.scss'
import { useActions, useValues } from 'kea'
import { router } from 'kea-router'
-import { useEffect, useState } from 'react'
+import { Suspense, lazy, useEffect, useState } from 'react'
import { IconArchive, IconCopy, IconPlusSmall, IconRewind, IconTrash } from '@posthog/icons'
import { LemonSkeleton } from '@posthog/lemon-ui'
@@ -30,7 +30,9 @@ import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'
import { userHasAccess } from 'lib/utils/accessControlUtils'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { addProductIntentForCrossSell } from 'lib/utils/product-intents'
+import { retryImport } from 'lib/utils/retryImport'
import { PendingChangeRequestBanner } from 'scenes/approvals/PendingChangeRequestBanner'
+import { ChunkLoadErrorBoundary } from 'scenes/ChunkLoadErrorBoundary'
import { Dashboard } from 'scenes/dashboard/Dashboard'
import { dashboardLogic } from 'scenes/dashboard/dashboardLogic'
import { EmptyDashboardComponent } from 'scenes/dashboard/EmptyDashboardComponent'
@@ -83,7 +85,6 @@ import { openFeatureFlagDeleteDialog } from './featureFlagDeleteDialog'
import { FeatureFlagEvaluationContexts } from './FeatureFlagEvaluationContexts'
import { ExperimentsTab } from './FeatureFlagExperimentsTab'
import { FeedbackTab } from './FeatureFlagFeedbackTab'
-import { FeatureFlagForm } from './FeatureFlagForm'
import { FeatureFlagLogicProps, featureFlagLogic } from './featureFlagLogic'
import { FeatureFlagOverview } from './FeatureFlagOverview'
import FeatureFlagProjects from './FeatureFlagProjects'
@@ -93,6 +94,24 @@ import { FeatureFlagTestingTab } from './FeatureFlagTestingTab'
const RESOURCE_TYPE = 'feature_flag'
+// The edit/create form pulls in heavy deps (dnd-kit, JSON editors, sortable release conditions).
+// Lazy-mounting it lets the Edit click flip state and paint a loading skeleton before that render,
+// instead of the click blocking the main thread for seconds and reading as a dead click.
+const FeatureFlagForm = lazy(() =>
+ retryImport(() => import('./FeatureFlagForm').then((m) => ({ default: m.FeatureFlagForm })))
+)
+
+function FeatureFlagFormSkeleton(): JSX.Element {
+ return (
+ <div className="deprecated-space-y-2">
+ <LemonSkeleton active className="h-4 w-2/5" />
+ <LemonSkeleton active className="h-4 w-full" />
+ <LemonSkeleton active className="h-4 w-full" />
+ <LemonSkeleton active className="h-4 w-3/5" />
+ </div>
+ )
+}
+
export const scene: SceneExport<FeatureFlagLogicProps> = {
component: FeatureFlag,
logic: featureFlagLogic,
@@ -160,6 +179,24 @@ export function FeatureFlag({ id }: FeatureFlagLogicProps): JSX.Element {
const isNewFeatureFlag = id === 'new' || id === undefined
+ // Mounting the edit form is a multi-second render (Monaco editors + dnd-kit sortables). Mount it
+ // immediately when the scene first renders already in form mode (deep-link/new flag), but when the
+ // user clicks Edit on the readonly view, defer one frame so the click flips state and the loading
+ // skeleton paints before that render — otherwise the click blocks the thread and reads as dead.
+ const shouldShowForm = isNewFeatureFlag || isEditingFlag
+ const [isFormMounted, setIsFormMounted] = useState(shouldShowForm)
+ useEffect(() => {
+ if (!shouldShowForm) {
+ setIsFormMounted(false)
+ return
+ }
+ if (isFormMounted) {
+ return
+ }
+ const raf = requestAnimationFrame(() => setIsFormMounted(true))
+ return () => cancelAnimationFrame(raf)
+ }, [shouldShowForm, isFormMounted])
+
useFileSystemLogView({
type: 'feature_flag',
ref: featureFlag?.id,
@@ -178,20 +215,22 @@ export function FeatureFlag({ id }: FeatureFlagLogicProps): JSX.Element {
}
if (featureFlagLoading) {
- return (
- <div className="deprecated-space-y-2">
- <LemonSkeleton active className="h-4 w-2/5" />
- <LemonSkeleton active className="h-4 w-full" />
- <LemonSkeleton active className="h-4 w-full" />
- <LemonSkeleton active className="h-4 w-3/5" />
- </div>
- )
+ return <FeatureFlagFormSkeleton />
}
// Use the form UI for creating new flags or editing existing flags.
// For viewing existing flags (readonly), use the tabbed UI below.
- if (isNewFeatureFlag || isEditingFlag) {
- return <FeatureFlagForm id={id} />
+ if (shouldShowForm) {
+ if (!isFormMounted) {
+ return <FeatureFlagFormSkeleton />
+ }
+ return (
+ <ChunkLoadErrorBoundary>
+ <Suspense fallback={<FeatureFlagFormSkeleton />}>
+ <FeatureFlagForm id={id} />
+ </Suspense>
+ </ChunkLoadErrorBoundary>
+ )
}
if (accessDeniedToFeatureFlag) {