: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
perf(frontend): load lemon markdown lazily in the authenticated shell (#126939)
Paul D'Ambra5f942e6cccf5
diff --git a/frontend/bin/check-eager-graph.mjs b/frontend/bin/check-eager-graph.mjsindex 0a044c6296ea..601a640eaf86 100644--- a/frontend/bin/check-eager-graph.mjs+++ b/frontend/bin/check-eager-graph.mjs@@ -104,8 +104,8 @@ const ROOTS = [{root: AUTHENTICATED_SHELL,label: 'authenticated shell (every logged-in page)',- // 2026-11-01: 5.55 MiB eager output, stable CSS included. ~0.3% headroom.- budgetBytes: 5_840_000,+ // 2026-11-01: 5.27 MiB eager output, stable CSS included. ~0.3% headroom.+ budgetBytes: 5_550_000,forbidden: ['node_modules/monaco-editor/','products/product_analytics/frontend/insights/activityDescriptions',@@ -138,6 +138,8 @@ const ROOTS = [// The RE2 regex engine checks regex filters before a query runs, and the shell runs no queries.// A hit means a module on the shell path imports lib/utils/regexp or re2js again.'node_modules/re2js/',+ // react-markdown and its remark plugins load on first render. Shell code uses LazyLemonMarkdown.+ 'node_modules/react-markdown/',// The zod-en-locale-only plugin in common/esbuilder/utils.mjs keeps every locale except// `en` out of the build. A hit on another locale means zod moved its locales barrel and// the plugin no longer matches it.@@ -181,8 +183,8 @@ const ROOTS = ['src/scenes/project-homepage/today/TodayHome.tsx',],label: 'today home path',- // 2026-11-01: 5.99 MiB, stable CSS included. ~0.3% headroom.- budgetBytes: 6_300_000,+ // 2026-11-01: 5.71 MiB, stable CSS included. ~0.3% headroom.+ budgetBytes: 6_010_000,forbidden: ['src/scenes/project-homepage/ai-first/AiFirstHomepage.tsx','src/scenes/project-homepage/today/TodayReportPage.tsx',diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityLogRow.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityLogRow.tsxindex 587f3ffec656..bab44d8590dc 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityLogRow.tsx+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityLogRow.tsx@@ -15,6 +15,7 @@ import {} from '@posthog/quill'import { ActivityClientTag } from 'lib/components/ActivityLog/ActivityClientTag'+import { ActivityLogDescription } from 'lib/components/ActivityLog/ActivityLogDescription'import { ActivityLogDiff } from 'lib/components/ActivityLog/ActivityLogDiff'import { ACTIVITY_SEARCH_PARAM } from 'lib/components/ActivityLog/activityLogLogic'import { AgentAttribution } from 'lib/components/ActivityLog/AgentAttribution'@@ -153,7 +154,9 @@ export function QuillActivityLogRow({ logItem }: { logItem: HumanizedActivityLog)}</>) : (- <div>{logItem.description}</div>+ <div>+ <ActivityLogDescription logItem={logItem} />+ </div>)}{logItem.extendedDescription && <div>{logItem.extendedDescription}</div>}<div className="empty:hidden">diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.tsxindex d9817e53688b..36a47982801b 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.tsx+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.tsx@@ -21,7 +21,6 @@ import { showCriticalNotificationToast } from 'lib/components/NotificationsMenu/import { FEATURE_FLAGS } from 'lib/constants'import { dayjs } from 'lib/dayjs'import { LemonDialog } from 'lib/lemon-ui/LemonDialog'-import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { liveEventsHostOrigin } from 'lib/utils/apiHost'import { retryWithBackoff } from 'lib/utils/async'@@ -1220,7 +1219,8 @@ export const sidePanelNotificationsLogic = kea<sidePanelNotificationsLogicType>(email: changelogNotification.email || '[email protected]',name: changelogNotification.name || 'Joe',isSystem: true,- description: <LemonMarkdown>{changelogNotification.markdown}</LemonMarkdown>,+ description: null,+ markdownDescription: changelogNotification.markdown,created_at: changelogNotification.notificationDate,unread: lastRead?.isSameOrBefore(changelogNotification.notificationDate),}) as HumanizedActivityLogItemdiff --git a/frontend/src/lib/components/ActivityLog/ActivityLogDescription.tsx b/frontend/src/lib/components/ActivityLog/ActivityLogDescription.tsxnew file mode 100644index 000000000000..9d72b30a26fa--- /dev/null+++ b/frontend/src/lib/components/ActivityLog/ActivityLogDescription.tsx@@ -0,0 +1,11 @@+import { LazyLemonMarkdown } from 'lib/lemon-ui/LemonMarkdown/LazyLemonMarkdown'++import { HumanizedActivityLogItem } from './humanizeActivity'++export function ActivityLogDescription({ logItem }: { logItem: HumanizedActivityLogItem }): JSX.Element {+ return logItem.markdownDescription ? (+ <LazyLemonMarkdown>{logItem.markdownDescription}</LazyLemonMarkdown>+ ) : (+ <>{logItem.description}</>+ )+}diff --git a/frontend/src/lib/components/ActivityLog/ActivityLogRow.test.tsx b/frontend/src/lib/components/ActivityLog/ActivityLogRow.test.tsxindex 3922cc566d01..0fff8bd3641e 100644--- a/frontend/src/lib/components/ActivityLog/ActivityLogRow.test.tsx+++ b/frontend/src/lib/components/ActivityLog/ActivityLogRow.test.tsx@@ -1,6 +1,6 @@import '@testing-library/jest-dom'-import { cleanup, fireEvent, render, screen } from '@testing-library/react'+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'import { Provider } from 'kea'import { ActivityLogRow } from 'lib/components/ActivityLog/ActivityLogRow'@@ -101,6 +101,28 @@ describe('ActivityLogRow', () => {expect(screen.queryByText('A user')).not.toBeInTheDocument()})+ it('passes a markdown description to the markdown renderer', async () => {+ const { container } = render(+ <Provider>+ <ActivityLogRow+ logItem={{+ name: 'Joe',+ isSystem: true,+ description: null,+ markdownDescription: 'Meet **session summaries**',+ created_at: dayjs(),+ }}+ />+ </Provider>+ )++ await waitFor(() =>+ expect(container.querySelector('[data-testid="react-markdown"]')).toHaveTextContent(+ 'Meet **session summaries**'+ )+ )+ })+test.each([['mcp', 'via MCP'],['scout:self-driving-dwh', 'via scout self-driving-dwh'],diff --git a/frontend/src/lib/components/ActivityLog/ActivityLogRow.tsx b/frontend/src/lib/components/ActivityLog/ActivityLogRow.tsxindex e214363e6456..31ceaf8ea0ba 100644--- a/frontend/src/lib/components/ActivityLog/ActivityLogRow.tsx+++ b/frontend/src/lib/components/ActivityLog/ActivityLogRow.tsx@@ -13,6 +13,7 @@ import { ProfilePicture } from 'lib/lemon-ui/ProfilePicture'import { copyToClipboard } from 'lib/utils/copyToClipboard'import { ActivityClientTag } from './ActivityClientTag'+import { ActivityLogDescription } from './ActivityLogDescription'import { ActivityLogDiff } from './ActivityLogDiff'import { ACTIVITY_SEARCH_PARAM } from './activityLogLogic'import { AgentAttribution } from './AgentAttribution'@@ -72,7 +73,11 @@ function ExpandedDetails({function RowSummary({ logItem, isExpanded }: { logItem: HumanizedActivityLogItem; isExpanded: boolean }): JSX.Element {if (!logItem.summary) {- return <div className="ActivityLogRow__description">{logItem.description}</div>+ return (+ <div className="ActivityLogRow__description">+ <ActivityLogDescription logItem={logItem} />+ </div>+ )}return (diff --git a/frontend/src/lib/components/ActivityLog/humanizeActivity.tsx b/frontend/src/lib/components/ActivityLog/humanizeActivity.tsxindex 012f693a116e..fa71a0eeb85b 100644--- a/frontend/src/lib/components/ActivityLog/humanizeActivity.tsx+++ b/frontend/src/lib/components/ActivityLog/humanizeActivity.tsx@@ -1,6 +1,6 @@import { UserNameWithEmail } from 'lib/components/ActivityLog/UserNameWithEmail'import { dayjs } from 'lib/dayjs'-import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'+import { LazyLemonMarkdown } from 'lib/lemon-ui/LemonMarkdown/LazyLemonMarkdown'import { fullName } from 'lib/utils/strings'import { ActivityScope, InsightShortId, PersonType, UserBasicType } from '~/types'@@ -96,6 +96,8 @@ export type HumanizedActivityLogItem = {/** SDK, integration, or scout that triggered this action. Self-reported through the x-posthog-client header, except for a scout, which the server names. */client?: string | nulldescription: Description+ /** Markdown the row renders in place of `description`, e.g. a changelog notification's body. */+ markdownDescription?: stringsummary?: ActivityLogSummaryextendedDescription?: ExtendedDescription // e.g. an insight's filters summaryexpandedView?: ExpandedView // e.g. a flag's release conditions after the change@@ -293,7 +295,7 @@ function describeComment(),extendedDescription: commentContent ? (<div className="border rounded bg-surface-primary p-4">- <LemonMarkdown lowKeyHeadings>{commentContent}</LemonMarkdown>+ <LazyLemonMarkdown lowKeyHeadings>{commentContent}</LazyLemonMarkdown></div>) : undefined,}diff --git a/frontend/src/lib/lemon-ui/LemonMarkdown/LazyLemonMarkdown.tsx b/frontend/src/lib/lemon-ui/LemonMarkdown/LazyLemonMarkdown.tsxnew file mode 100644index 000000000000..425b67ee0ca1--- /dev/null+++ b/frontend/src/lib/lemon-ui/LemonMarkdown/LazyLemonMarkdown.tsx@@ -0,0 +1,29 @@+import clsx from 'clsx'+import { Suspense } from 'react'++import { lazyWithRetry } from 'lib/utils/retryImport'++import type { LemonMarkdownProps } from './LemonMarkdown'++const LemonMarkdownChunk = lazyWithRetry(() => import('./LemonMarkdown').then((m) => ({ default: m.LemonMarkdown })))++/**+ * `LemonMarkdown` loaded on first render. Use it in code that ships on every page.+ * While the chunk loads, the raw text holds roughly the rendered height invisibly, so content below does not jump.+ */+export function LazyLemonMarkdown(props: LemonMarkdownProps): JSX.Element {+ return (+ <Suspense+ fallback={+ <div+ className={clsx('invisible whitespace-pre-line [overflow-wrap:anywhere]', props.className)}+ aria-busy+ >+ {props.children}+ </div>+ }+ >+ <LemonMarkdownChunk {...props} />+ </Suspense>+ )+}diff --git a/frontend/src/scenes/onboarding/shared/wizard-sync/WizardHandoffDialog.tsx b/frontend/src/scenes/onboarding/shared/wizard-sync/WizardHandoffDialog.tsxindex 1e5bc5b01cca..b59d17011326 100644--- a/frontend/src/scenes/onboarding/shared/wizard-sync/WizardHandoffDialog.tsx+++ b/frontend/src/scenes/onboarding/shared/wizard-sync/WizardHandoffDialog.tsx@@ -2,7 +2,7 @@ import { useActions, useValues } from 'kea'import { LemonModal } from '@posthog/lemon-ui'-import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'+import { LazyLemonMarkdown } from 'lib/lemon-ui/LemonMarkdown/LazyLemonMarkdown'import { wizardSyncUiLogic } from './wizardSyncUiLogic'@@ -32,7 +32,7 @@ export function WizardHandoffDialog(): JSX.Element {names, framework detail) and must not reach autocapture. disableImages: the text isagent output, so an inline image would fire a request to an arbitrary URL. */}<div className="ph-no-capture" data-attr="wizard-handoff-doc">- <LemonMarkdown disableImages>{handoffDoc?.text ?? ''}</LemonMarkdown>+ <LazyLemonMarkdown disableImages>{handoffDoc?.text ?? ''}</LazyLemonMarkdown></div></LemonModal>)