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(feature-flags): only mount QuickSurveyModal when open (#58247)

Paul D'Ambra34351308b839
diff --git a/frontend/src/scenes/surveys/QuickSurveyModal.tsx b/frontend/src/scenes/surveys/QuickSurveyModal.tsx
index bc718e1c87aa..bae8d4e31016 100644
--- a/frontend/src/scenes/surveys/QuickSurveyModal.tsx
+++ b/frontend/src/scenes/surveys/QuickSurveyModal.tsx
@@ -1,6 +1,6 @@
import { BindLogic, useActions, useValues } from 'kea'
import { SurveyQuestionType } from 'posthog-js'
-import { useMemo, useRef } from 'react'
+import { useEffect, useMemo, useRef, useState } from 'react'
import {
LemonBanner,
@@ -287,9 +287,32 @@ export function QuickSurveyModal({
isOpen: boolean
modalTitle?: string
showFollowupToggle?: boolean
-}): JSX.Element {
+}): JSX.Element | null {
+ // Lazy mount: callers may render <QuickSurveyModal> per row (e.g. in a
+ // 100-row feature-flags table). Always-mounting the underlying
+ // react-modal allocates a portal container and ~130 delegated event
+ // listeners per instance even while closed, which adds up to tens of
+ // thousands of listeners. Track mount-state internally so the portal
+ // only exists while the modal is open, while still passing isOpen
+ // through to LemonModal so its 250ms close transition can play
+ // before onAfterClose tears the portal down.
+ const [isMounted, setIsMounted] = useState(isOpen)
+ useEffect(() => {
+ if (isOpen) {
+ setIsMounted(true)
+ }
+ }, [isOpen])
+ if (!isMounted) {
+ return null
+ }
return (
- <LemonModal title={modalTitle || 'Quick feedback survey'} isOpen={isOpen} onClose={onCancel} width={900}>
+ <LemonModal
+ title={modalTitle || 'Quick feedback survey'}
+ isOpen={isOpen}
+ onClose={onCancel}
+ onAfterClose={() => setIsMounted(false)}
+ width={900}
+ >
{context && (
<QuickSurveyForm
context={context}