: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
fix(experiments): re-apply collapse control for long conclusion texts (#106151)
Rodrigo Iloro58f08730654c
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex ba3b5fb27800..e3e26a541ddc 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -8705,9 +8705,9 @@ snapshots:scenes-app-experiments--experiment-stopped-with-conclusion--light:hash: v1.k794b7964.c78a986cd9513aba12171b8f48b6f1ec6139366a1f5360ab4a2137741a51e278.JYMHGSTMhmhKgGyfMaOqFxfIRd1a3wnA4huRtddfrW8scenes-app-experiments--experiment-stopped-with-long-conclusion--dark:- hash: v1.k794b7964.6576d52628510db74ec27c57edb02b8c8d064180c4dc98c96b02885a2c96f6a8.mck96sj9PrHVG0cuEp6wDruUNkEXgSOJxrS4UKWU1M4+ hash: v1.k794b7964.37dc8c30ff2c9668f81edfd777d718f3ca163850c13ccfc1c47869a415d51c25.MD3L0Iud7jDRTpWjHOx8iL-uzoCyrcDAFBolHbhPzaMscenes-app-experiments--experiment-stopped-with-long-conclusion--light:- hash: v1.k794b7964.1490eb3623f81b61948f41927cab834904615dff4a6082bd2c946720bbad2b89.Q9Lmvd1WzVbX0cRiA9o2Vy0MH4ec3V-aMLhvMmJitb8+ hash: v1.k794b7964.a57a3d4e1af54d4fe4d12a6f23e5a11c3328d78ea5fb24dff56135205833d569.XXqmXrrOPEQE9xdp2mn-1bJoORNh3S-xbME65apRYswscenes-app-experiments--experiment-watch-shelf-no-recordings--dark:hash: v1.k794b7964.b0a33d4938ed61c630ce999c01bd9cef54b028fcba6dad76ed3d661dbc2dd99d.2aGTSasozsT731r8a62vkXfonYkviSdtLTr-2s4W6DIscenes-app-experiments--experiment-watch-shelf-no-recordings--light:diff --git a/products/experiments/frontend/components/ExperimentMetaBar/ExperimentConclusionCard.tsx b/products/experiments/frontend/components/ExperimentMetaBar/ExperimentConclusionCard.tsxindex 81500b34f0f6..f013fe6043ea 100644--- a/products/experiments/frontend/components/ExperimentMetaBar/ExperimentConclusionCard.tsx+++ b/products/experiments/frontend/components/ExperimentMetaBar/ExperimentConclusionCard.tsx@@ -6,6 +6,8 @@ import { LemonButton } from '@posthog/lemon-ui'import { experimentLogic } from 'scenes/experiments/experimentLogic'import { modalsLogic } from 'scenes/experiments/modalsLogic'+import { ExperimentConclusionComment } from './ExperimentConclusionComment'+// Mirrors the Hypothesis card in the Metrics tab so the two read as one family.export function ExperimentConclusionCard(): JSX.Element | null {const { experiment } = useValues(experimentLogic)@@ -32,9 +34,7 @@ export function ExperimentConclusionCard(): JSX.Element | null {/></div>{experiment.conclusion_comment ? (- <p className="metric-cell font-normal m-0 mt-1 leading-relaxed whitespace-pre-wrap">- {experiment.conclusion_comment}- </p>+ <ExperimentConclusionComment comment={experiment.conclusion_comment} />) : (<p className="metric-cell font-normal m-0 mt-1 leading-relaxed italic">Add a note about why this experiment endeddiff --git a/products/experiments/frontend/components/ExperimentMetaBar/ExperimentConclusionComment.test.tsx b/products/experiments/frontend/components/ExperimentMetaBar/ExperimentConclusionComment.test.tsxnew file mode 100644index 000000000000..278cd36b2b81--- /dev/null+++ b/products/experiments/frontend/components/ExperimentMetaBar/ExperimentConclusionComment.test.tsx@@ -0,0 +1,45 @@+import { fireEvent, render, screen } from '@testing-library/react'++import { ExperimentConclusionComment } from './ExperimentConclusionComment'++// jsdom has no layout, so the collapsed height and the full text height are stubbed per case.+const COLLAPSED_HEIGHT = 144++describe('ExperimentConclusionComment', () => {+ const clientHeight = Object.getOwnPropertyDescriptor(Element.prototype, 'clientHeight')+ const scrollHeight = Object.getOwnPropertyDescriptor(Element.prototype, 'scrollHeight')++ function mockTextHeight(fullHeight: number): void {+ Object.defineProperty(Element.prototype, 'clientHeight', { configurable: true, get: () => COLLAPSED_HEIGHT })+ Object.defineProperty(Element.prototype, 'scrollHeight', { configurable: true, get: () => fullHeight })+ }++ afterEach(() => {+ Object.defineProperty(Element.prototype, 'clientHeight', clientHeight!)+ Object.defineProperty(Element.prototype, 'scrollHeight', scrollHeight!)+ })++ it('shows no toggle when the comment fits', () => {+ mockTextHeight(COLLAPSED_HEIGHT)+ render(<ExperimentConclusionComment comment="Shipped it." />)++ expect(screen.queryByTestId('experiment-conclusion-toggle')).toBeNull()+ })++ it('expands and collapses a comment taller than the cap', () => {+ mockTextHeight(COLLAPSED_HEIGHT * 4)+ render(<ExperimentConclusionComment comment="A long conclusion." />)++ const toggle = screen.getByTestId('experiment-conclusion-toggle')+ expect(toggle.textContent).toBe('Show more')+ expect(toggle.getAttribute('aria-expanded')).toBe('false')++ fireEvent.click(toggle)+ expect(toggle.textContent).toBe('Show less')+ expect(toggle.getAttribute('aria-expanded')).toBe('true')++ fireEvent.click(toggle)+ expect(toggle.textContent).toBe('Show more')+ expect(toggle.getAttribute('aria-expanded')).toBe('false')+ })+})diff --git a/frontend/src/scenes/experiments/ExperimentView/ConclusionComment.tsx b/products/experiments/frontend/components/ExperimentMetaBar/ExperimentConclusionComment.tsxsimilarity index 90%rename from frontend/src/scenes/experiments/ExperimentView/ConclusionComment.tsxrename to products/experiments/frontend/components/ExperimentMetaBar/ExperimentConclusionComment.tsxindex 83c83362849c..ea9d85112598 100644--- a/frontend/src/scenes/experiments/ExperimentView/ConclusionComment.tsx+++ b/products/experiments/frontend/components/ExperimentMetaBar/ExperimentConclusionComment.tsx@@ -1,9 +1,10 @@-import clsx from 'clsx'import { useLayoutEffect, useRef, useState } from 'react'import { LemonButton } from '@posthog/lemon-ui'-export function ConclusionComment({ comment }: { comment: string }): JSX.Element {+import { cn } from 'lib/utils/css-classes'++export function ExperimentConclusionComment({ comment }: { comment: string }): JSX.Element {const [isExpanded, setIsExpanded] = useState(false)const [isOverflowing, setIsOverflowing] = useState(false)const textRef = useRef<HTMLParagraphElement>(null)@@ -28,7 +29,7 @@ export function ConclusionComment({ comment }: { comment: string }): JSX.Element<pref={textRef}id="experiment-conclusion-comment-text"- className={clsx(+ className={cn('metric-cell font-normal m-0 mt-1 leading-relaxed whitespace-pre-wrap break-words',!isExpanded && 'max-h-36 overflow-hidden')}