: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
chore(frontend): keep the rich text editor off the authenticated shell (#126879)
Paul D'Ambra9da916dc3d9c
diff --git a/frontend/bin/check-eager-graph.mjs b/frontend/bin/check-eager-graph.mjsindex 7ca513c77e4c..c3419b771fe7 100644--- a/frontend/bin/check-eager-graph.mjs+++ b/frontend/bin/check-eager-graph.mjs@@ -128,6 +128,9 @@ const ROOTS = ['src/layout/today/TodayTopBar.tsx',// The rail's pane actions pull in the new-analytics menu and the canvas block library.'src/layout/today/todayRailItems.tsx',+ // The rich text editor stack is for the scenes that edit text. Rendered markdown needs none of it.+ 'node_modules/@tiptap/',+ 'node_modules/prosemirror-',// 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.diff --git a/frontend/bin/layer-baseline.txt b/frontend/bin/layer-baseline.txtindex ff80177f2ed8..b5afe6210767 100644--- a/frontend/bin/layer-baseline.txt+++ b/frontend/bin/layer-baseline.txt@@ -340,7 +340,6 @@ frontend/src/lib/lemon-ui/LemonColor/LemonColorGlyph.tsx -> frontend/src/lib/logfrontend/src/lib/lemon-ui/LemonColor/LemonColorPicker.tsx -> frontend/src/lib/logic/dataThemeLogic.tsxfrontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.tsx -> frontend/src/lib/components/AutoSizer/index.tsfrontend/src/lib/lemon-ui/LemonMarkdown/LemonMarkdown.tsx -> frontend/src/lib/components/CodeSnippet/index.ts-frontend/src/lib/lemon-ui/LemonMarkdown/LemonMarkdown.tsx -> frontend/src/lib/components/RichContentEditor/RichContentNodeMention.tsxfrontend/src/lib/lemon-ui/LemonMarkdown/MermaidDiagram.tsx -> frontend/src/lib/components/CodeSnippet/index.tsfrontend/src/lib/lemon-ui/LemonMarkdown/MermaidDiagram.tsx -> frontend/src/lib/logic/themeLogic.tsfrontend/src/lib/lemon-ui/LemonMarkdown/mention.ts -> frontend/src/lib/components/RichContentEditor/types.tsdiff --git a/frontend/src/lib/components/RichContentEditor/RichContentMention.tsx b/frontend/src/lib/components/RichContentEditor/RichContentMention.tsxnew file mode 100644index 000000000000..a665bb4eeba5--- /dev/null+++ b/frontend/src/lib/components/RichContentEditor/RichContentMention.tsx@@ -0,0 +1,29 @@+import { useValues } from 'kea'++import { ProfilePicture, Tooltip } from '@posthog/lemon-ui'++import { membersLogic } from '~/models/membersLogic'++export const RichContentMention = ({ id }: { id?: number }): JSX.Element => {+ const { meFirstMembers } = useValues(membersLogic)++ const member = meFirstMembers.find((member) => member.user.id === id)++ return (+ <Tooltip+ title={+ <div className="p-2 flex items-center gap-2">+ <ProfilePicture user={member?.user} size="xl" />+ <div className="ph-no-capture">+ <div className="font-bold">{member?.user.first_name}</div>+ <div className="text-sm">{member?.user.email}</div>+ </div>+ </div>+ }+ >+ <span className="ph-no-capture bg-fill-highlight-100 px-1 rounded font-medium">+ @{member?.user.first_name ?? '(Member)'}+ </span>+ </Tooltip>+ )+}diff --git a/frontend/src/lib/components/RichContentEditor/RichContentNodeMention.tsx b/frontend/src/lib/components/RichContentEditor/RichContentNodeMention.tsxindex e24418818d82..94df67fbc401 100644--- a/frontend/src/lib/components/RichContentEditor/RichContentNodeMention.tsx+++ b/frontend/src/lib/components/RichContentEditor/RichContentNodeMention.tsx@@ -1,12 +1,8 @@import { Node, NodeViewProps, mergeAttributes } from '@tiptap/core'import { NodeViewWrapper, ReactNodeViewRenderer } from '@tiptap/react'import clsx from 'clsx'-import { useValues } from 'kea'--import { ProfilePicture, Tooltip } from '@posthog/lemon-ui'--import { membersLogic } from '~/models/membersLogic'+import { RichContentMention } from './RichContentMention'import { RichContentNodeType } from './types'export interface RichContentNodeMentionAttrs {@@ -26,30 +22,6 @@ const Component = (props: NodeViewProps): JSX.Element => {)}-export const RichContentMention = ({ id }: { id?: number }): JSX.Element => {- const { meFirstMembers } = useValues(membersLogic)-- const member = meFirstMembers.find((member) => member.user.id === id)-- return (- <Tooltip- title={- <div className="p-2 flex items-center gap-2">- <ProfilePicture user={member?.user} size="xl" />- <div className="ph-no-capture">- <div className="font-bold">{member?.user.first_name}</div>- <div className="text-sm">{member?.user.email}</div>- </div>- </div>- }- >- <span className="ph-no-capture bg-fill-highlight-100 px-1 rounded font-medium">- @{member?.user.first_name ?? '(Member)'}- </span>- </Tooltip>- )-}-export const RichContentNodeMention = Node.create({name: RichContentNodeType.Mention,inline: true,diff --git a/frontend/src/lib/lemon-ui/LemonMarkdown/LemonMarkdown.tsx b/frontend/src/lib/lemon-ui/LemonMarkdown/LemonMarkdown.tsxindex 0f2b60bb1974..e89c05bc38f4 100644--- a/frontend/src/lib/lemon-ui/LemonMarkdown/LemonMarkdown.tsx+++ b/frontend/src/lib/lemon-ui/LemonMarkdown/LemonMarkdown.tsx@@ -1,19 +1,26 @@import './LemonMarkdown.scss'import clsx from 'clsx'-import React, { memo, useMemo } from 'react'+import React, { Suspense, memo, useMemo } from 'react'import ReactMarkdown, { type Components, defaultUrlTransform } from 'react-markdown'import remarkBreaks from 'remark-breaks'import remarkGfm from 'remark-gfm'import { CodeSnippet, getLanguage, Language } from 'lib/components/CodeSnippet'-import { RichContentMention } from 'lib/components/RichContentEditor/RichContentNodeMention'import { LemonCheckbox } from 'lib/lemon-ui/LemonCheckbox'+import { lazyWithRetry } from 'lib/utils/retryImport'import { isTrustedPostHogUrl } from 'lib/utils/trustedUrl'import { Link } from '../Link'import remarkMentions from './mention'+// lemon-ui must not statically import app code, and the mention chip reads members from membersLogic.+const RichContentMention = lazyWithRetry(() =>+ import('lib/components/RichContentEditor/RichContentMention').then((module) => ({+ default: module.RichContentMention,+ }))+)+/*** Link target that places a chart inline in prose, e.g. `[Daily signups](chart:signups-drop)`.* A link rather than a bespoke token so the same markdown degrades to a readable label in the@@ -270,7 +277,11 @@ const LemonMarkdownRenderer = memo(function LemonMarkdownRenderer({),span: ({ className, ...props }: any): JSX.Element => {if (className === 'ph-mention') {- return <RichContentMention id={Number(props['data-mention-id'])} />+ return (+ <Suspense fallback={<span className="bg-fill-highlight-100 px-1 rounded font-medium">@</span>}>+ <RichContentMention id={Number(props['data-mention-id'])} />+ </Suspense>+ )}return <span className={className} {...props} />},