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(phai): cut per-keystroke work in legacy thread view (#69399)

Georgiy Tarasov27b0c950c5c1
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index cb803eb75842..2607ae25ca73 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -4547,33 +4547,33 @@ snapshots:
products-data-modeling-lineage-graph--single-node--light:
hash: v1.k794b7964.965d630c09110769bac58d2fc162856dc5303d9a98e97995aec4cc48098581da.Gi_VbiOcJVaHaHybXL8911KOWXwBMAGtbHwCIA2HO0E
products-posthog-ai-composer--default--dark:
- hash: v1.k794b7964.46b58701d85781d463019c60ff4249a090bf3997b48bce436de397764443a239.r1kxyzWoJ0j9b9_aBUh9MByfQRFFKUkIP9a8eYD9qCQ
+ hash: v1.k794b7964.4ccf5eb666de2b3315dc3f142ded80b445748d58ce8ae2d7d154272d7b194b3b.E61uR16UwC5qC1XkQquxMh1z3bonN6IYLdYDyzcorTA
products-posthog-ai-composer--default--light:
- hash: v1.k794b7964.be07c7ce42d999598811678f63b63aa314bc654339e28c4fc0509002e14a0027.5EojcUuBOtRxaf2AzgK4fsuxj3Pm4HKX3uI2xdW9Jj0
+ hash: v1.k794b7964.c05f338ff4a0eb1317b8c10a45f62e9369d453338567690d98aad588bbb3e052.vMaiwV6AjlHPYwFhvcMfUx1GTX8QIfDYlofgldtSY8w
products-posthog-ai-composer--disabled--dark:
- hash: v1.k794b7964.46b58701d85781d463019c60ff4249a090bf3997b48bce436de397764443a239.PA5jTdAlMaLlGPy17mYmVWNVz-6PPqU0q6X3UKwXhs0
+ hash: v1.k794b7964.4ccf5eb666de2b3315dc3f142ded80b445748d58ce8ae2d7d154272d7b194b3b.GZXszXQ19-vaAtfrA0TA9whSgdKzZ2uWMatck_t2cn8
products-posthog-ai-composer--disabled--light:
- hash: v1.k794b7964.be07c7ce42d999598811678f63b63aa314bc654339e28c4fc0509002e14a0027.ABS00oRzoMx2ZPOAa10BxrWeJkiGagHnstIIsrRKFpg
+ hash: v1.k794b7964.c05f338ff4a0eb1317b8c10a45f62e9369d453338567690d98aad588bbb3e052.4FLfOe11pP2xuuFyF8-JBXDjyB4WCWgSn6swEFDpZlY
products-posthog-ai-composer--filled--dark:
- hash: v1.k794b7964.3cc118c848f2014aa5c227880c5568e2e53e5d597850dd8c59ce92c765924a49.MAFXYb0oiVLhoyJ47PwPNo81ZrR93qLxuq9Zevv_XEE
+ hash: v1.k794b7964.cad4f6cb3968e1749346a1fa16b4c80f181a8179ff16719daab603f61e1c3a66.5qaQqKeNCAGKe9mpch7l_ITo7e9lsgh1AaKhKgMfkYg
products-posthog-ai-composer--filled--light:
- hash: v1.k794b7964.2aa3efd7d256b43dd5bc4e2d79c38637e538fedc5a894ef029c3891c85f5c2db.Dq9JqVwFXNP23I6fjnG5Vlm7Zs-5EyubrZ9dvfT--cw
+ hash: v1.k794b7964.7951d540b52889083aa1ab997c276b3eecc5a9e9efcd74fc3af89f919d250e27.C54RQPQyIDovJNUYB2T764siz0fOBAcX7Uz2GcZhnYQ
products-posthog-ai-composer--follow-up--dark:
- hash: v1.k794b7964.38b7d94b57b3ed964e0a0ceb7908f95136fa59f0496116c4f0dae2b55e65502d.GFvNpZtHbnwiyvuCznLRRwChoY4FYjkqnLCD5C9faLQ
+ hash: v1.k794b7964.dee38622789bbe9a3b07e09ab36d5b1b7c9eb26463df50006ac3a2ffe153aaf7.UDrsK8EQc6sVVM_JaxysboTKsh9m8HhSWWlLgsHgjA4
products-posthog-ai-composer--follow-up--light:
- hash: v1.k794b7964.d85d6336cdbb067b045d6c5c5683f61937ea7ff8cf0ee1a058a302ba252b76d3._Ge5IgxWN900F4ub2TfPHafDxZ3zlXPRBN5Jf5F--OA
+ hash: v1.k794b7964.de1b5807b60110b55f3cd9aee4d93ec17c3ea9dc887b7d4bc6d0ff158fdedcd2.h3WAEGykdXg5ekvSVkY94k_0HXzUx93TSEF3qQRCEI8
products-posthog-ai-composer--sticky--dark:
- hash: v1.k794b7964.1e4a68786ddf18c54f6cb1c705f31e8c9c8b0a3dfd533f1a7f29eb5078388226.vH3ZMS3ri4ku9tAFdMWsCzgiL7PY3DU2WcIV1-a35R8
+ hash: v1.k794b7964.de4a523033a10250834aa0917403e6ec61e3d3cdd99300830676e6ba81869e5b.AD54AJl9xbBHB2tql3MqC62FAcU85AgoIV4-aEgzV3s
products-posthog-ai-composer--sticky--light:
- hash: v1.k794b7964.f5e0899993568ec282e1323e0623e4da892d4fe1f72f05a6193750811644ccf9.XcQWY-4yjXcX917lNL2hrmwneB6wOOzV54JtrFvtUes
+ hash: v1.k794b7964.91c7a1b9be80ab39efcb23561be33d7431da793f1e254a9dc4341515603767b6.zTpu8qftYG9C2ZtNdxPVN6GAx47a4kCDE6JGUOd-UJ8
products-posthog-ai-composer--with-footer--dark:
- hash: v1.k794b7964.0c470ab933ccfcf3ac3efdee18bcddf901f93297a512caf508514728f13407c5.rhKRUzmJt0iOO2xiKpU49-jCnmOG9ANQXL2o_dImiH8
+ hash: v1.k794b7964.e977c79afa7cb140f9a12a3b293a7b5f4274b0c847df0570fbd7405b2c6fe2ac.p7BBWHL-FLdmdqwtVGk_J0vB2r3rh2VapbBAr0Hk-w4
products-posthog-ai-composer--with-footer--light:
- hash: v1.k794b7964.4373d41d53166542a39af8ccb802c6f32de9f58e14c274fd09f7f7e7f193d891.JRQl6GmryXSHZunbeYYKBzZGg6huT62z_VbQtRnrdoo
+ hash: v1.k794b7964.b0f44b7692f6ad25f611d7a2a33c1cfbd67b66c7c884617a09eb5c4c8f5cb887.oWsTs14NYxOkVJ_dZdLZJAvmERZeHYqYM-T4YH9AXGU
products-posthog-ai-composer--with-up-next-queue--dark:
- hash: v1.k794b7964.140c0f20b63444bf9f2f9a6ba00798b90243f5f43cff4aaf01fb226b732c557b.RvfMzUqid4-6uiSvPjbdwk9NLfDOesIzOCrGBMoTSio
+ hash: v1.k794b7964.e893edaa31202a96439233ff254af446b1ae72107ca4d187a0ab27abc87db8ac.ClRtYW3AIl8tt8UNlaLx_52ymgYxs4FUUHPusEIzAs8
products-posthog-ai-composer--with-up-next-queue--light:
- hash: v1.k794b7964.b7e1c8da8701294265a9abf4722bad1e4a89299b4e92965b4676da67088feb47.fp3qfFzcx1YFlYJqOmrym-v4SNYLKKSgSsesPc8gAME
+ hash: v1.k794b7964.c6aa2aa587283120fba069845efe3f499ad93f57f01a44fe60714bf6de06aa77.sXADx8Z_E97Ez10RF94ejn6saVtul9mmzMW6g6F-M8U
products-posthog-ai-queuedmessagelist--empty--dark:
hash: v1.k794b7964.4313fbb59e762d6fc4a87fed828bb6c814697c489997e23111f95df3d84be347.VRvN01m1Gf36IcNO8lzu8q3mqxKWwSRROgPqtbxMiSU
products-posthog-ai-queuedmessagelist--empty--light:
diff --git a/frontend/src/scenes/max/Context.tsx b/frontend/src/scenes/max/Context.tsx
index 5e0bd6008a92..5ca087c62d83 100644
--- a/frontend/src/scenes/max/Context.tsx
+++ b/frontend/src/scenes/max/Context.tsx
@@ -367,7 +367,12 @@ interface ContextDisplayProps {
size?: 'small' | 'default'
}
-export function ContextDisplay({ size = 'default' }: ContextDisplayProps): JSX.Element | null {
+// Memoized: QuestionInput re-renders on every keystroke (local input state), and this subtree
+// (ModeSelector, TaxonomicPopover, context tags with tooltips) is its most expensive part while
+// being keystroke-independent. useValues subscriptions inside still trigger their own re-renders.
+export const ContextDisplay = React.memo(function ContextDisplay({
+ size = 'default',
+}: ContextDisplayProps): JSX.Element | null {
const { showContextUI, contextDisabledReason, conversation, sandboxConversationKey } = useValues(maxThreadLogic)
const isSandboxRuntime = conversation?.agent_runtime === 'sandbox'
const { hasData, contextOptions, taxonomicGroupTypes, mainTaxonomicGroupType, toolContextItems } =
@@ -422,4 +427,4 @@ export function ContextDisplay({ size = 'default' }: ContextDisplayProps): JSX.E
</div>
</div>
)
-}
+})
diff --git a/frontend/src/scenes/max/Thread.tsx b/frontend/src/scenes/max/Thread.tsx
index 651375267b83..186fcd346e11 100644
--- a/frontend/src/scenes/max/Thread.tsx
+++ b/frontend/src/scenes/max/Thread.tsx
@@ -446,6 +446,11 @@ function MessageContainer({
<div
className={cn(
'relative flex',
+ // Off-screen messages (insight cards especially) otherwise participate in every
+ // style recalc / layout / paint the composer triggers while typing, which makes
+ // keystroke latency grow with thread length. `auto 100px` is only the pre-first-render
+ // estimate; after a message renders once, the browser remembers its real size.
+ '[content-visibility:auto] [contain-intrinsic-size:auto_100px]',
groupType === 'human' ? 'flex-row-reverse ml-4 @md/thread:ml-10 ' : 'mr-4 @md/thread:mr-10',
className
)}
diff --git a/frontend/src/scenes/max/components/AiFirstMaxInstance.tsx b/frontend/src/scenes/max/components/AiFirstMaxInstance.tsx
index 41d67cc21167..1dccae5d7d8c 100644
--- a/frontend/src/scenes/max/components/AiFirstMaxInstance.tsx
+++ b/frontend/src/scenes/max/components/AiFirstMaxInstance.tsx
@@ -159,7 +159,7 @@ function ChatArea({ threadVisible, conversation, onStartNewConversation }: ChatA
{/* Intro - fades out when messages appear */}
<div
- className={`flex flex-col items-center transition-all duration-200 ease-out ${
+ className={`flex flex-col items-center transition-[opacity,height,padding] duration-200 ease-out ${
hasMessages ? 'opacity-0 h-0 overflow-hidden' : 'opacity-100 pb-3'
}`}
>
@@ -187,7 +187,7 @@ function ChatArea({ threadVisible, conversation, onStartNewConversation }: ChatA
{/* Input - always in flow, mt-auto pushes to bottom when messages exist */}
<div
- className={`w-full max-w-3xl mx-auto px-4 transition-all duration-300 ease-out z-50 ${
+ className={`w-full max-w-3xl mx-auto px-4 transition-[max-width,padding,background-color] duration-300 ease-out z-50 ${
hasMessages ? 'sticky bottom-0 bg-primary py-2 max-w-none' : 'pb-4'
}`}
>
diff --git a/frontend/src/scenes/max/components/QuestionInput.tsx b/frontend/src/scenes/max/components/QuestionInput.tsx
index 29df9acf76a0..f6842aa7e79f 100644
--- a/frontend/src/scenes/max/components/QuestionInput.tsx
+++ b/frontend/src/scenes/max/components/QuestionInput.tsx
@@ -7,7 +7,7 @@ import React, { ReactNode, useEffect, useMemo, useRef, useState } from 'react'
import { useDebouncedCallback } from 'use-debounce'
import { IconArrowRight, IconCheck, IconPencil, IconStopFilled, IconTrash, IconX } from '@posthog/icons'
-import { LemonButton, LemonSwitch, LemonTextArea, Spinner } from '@posthog/lemon-ui'
+import { LemonButton, LemonSwitch, Spinner } from '@posthog/lemon-ui'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { cn } from 'lib/utils/css-classes'
@@ -18,6 +18,8 @@ import { KeyboardShortcut } from '~/layout/navigation-3000/components/KeyboardSh
import { AgentMode } from '~/queries/schema/schema-assistant-messages'
import { ConversationQueueMessage } from '~/types'
+import { AutosizeTextArea } from 'products/posthog_ai/frontend/api/primitives'
+
import { ContextDisplay } from '../Context'
import { handsFreeLogic } from '../handsFreeLogic'
import { maxGlobalLogic } from '../maxGlobalLogic'
@@ -75,7 +77,7 @@ function QueuedMessageItem({
if (isEditing) {
return (
<div className="space-y-2">
- <LemonTextArea
+ <AutosizeTextArea
ref={textAreaRef}
value={draft}
onChange={setDraft}
@@ -388,7 +390,7 @@ export const QuestionInput = React.forwardRef<HTMLDivElement, QuestionInputProps
<FillInHint text={inputValue} hint={fillInHint} />
</div>
)}
- <LemonTextArea
+ <AutosizeTextArea
aria-describedby={!inputValue ? 'textarea-hint' : undefined}
id="question-input"
data-attr="max-chat-input"
@@ -446,8 +448,9 @@ export const QuestionInput = React.forwardRef<HTMLDivElement, QuestionInputProps
disabled={inputDisabled}
minRows={1}
maxRows={10}
- className={cn(
- '!border-none !bg-transparent min-h-16 py-2 pl-2 resize-none',
+ className="py-2 pl-2"
+ textareaClassName={cn(
+ '!border-none !bg-transparent min-h-16 resize-none',
handsFreeFlagEnabled ? 'pr-20' : 'pr-12',
// Hide the native caret so only the enlarged fill-in caret shows.
showFillInHint && 'caret-transparent'
diff --git a/frontend/src/scenes/max/components/SlashCommandAutocomplete.tsx b/frontend/src/scenes/max/components/SlashCommandAutocomplete.tsx
index ae97588e680a..73d4cf40ccca 100644
--- a/frontend/src/scenes/max/components/SlashCommandAutocomplete.tsx
+++ b/frontend/src/scenes/max/components/SlashCommandAutocomplete.tsx
@@ -67,7 +67,7 @@ export function SlashCommandAutocomplete({ onClose, visible, children }: SlashCo
activateCommand(filteredCommands[activeItemIndex])
}
}
- document.addEventListener('keydown', handleKeyDown, { capture: true }) // Capture phase to run this before LemonTextArea's onEnter
+ document.addEventListener('keydown', handleKeyDown, { capture: true }) // Capture phase to run this before AutosizeTextArea's onEnter
return () => document.removeEventListener('keydown', handleKeyDown, { capture: true })
}, [visible, filteredCommands, activeItemIndex, activateCommand, selectCommand, onClose])
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index b6d7a1cf6fe0..b8992d87770e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -3885,6 +3885,9 @@ importers:
react-intersection-observer:
specifier: ^9.5.3
version: 9.5.3([email protected])
+ react-textarea-autosize:
+ specifier: '*'
+ version: 8.5.9(@types/[email protected])([email protected])
tailwind-merge:
specifier: '*'
version: 2.2.2
diff --git a/products/posthog_ai/frontend/api/primitives.ts b/products/posthog_ai/frontend/api/primitives.ts
index 60813dff43fd..b95e3211fa80 100644
--- a/products/posthog_ai/frontend/api/primitives.ts
+++ b/products/posthog_ai/frontend/api/primitives.ts
@@ -19,6 +19,11 @@ export type {
ComposerSubmitProps,
} from '../components/composer/Composer'
+// Self-sizing textarea (native field-sizing with a react-textarea-autosize fallback) — the input
+// element behind Composer.Textarea, for surfaces that need the bare control (e.g. message editing).
+export { AutosizeTextArea } from '../components/AutosizeTextArea'
+export type { AutosizeTextAreaProps } from '../components/AutosizeTextArea'
+
// Controlled model + reasoning-effort pickers for a composer footer.
export { ComposerModelEffortPickers } from '../components/composer/ComposerModelEffortPickers'
export type { ComposerModelEffortPickersProps } from '../components/composer/ComposerModelEffortPickers'
diff --git a/products/posthog_ai/frontend/components/ActivityPrimitives.tsx b/products/posthog_ai/frontend/components/ActivityPrimitives.tsx
index cc5a039f1467..81db70374fad 100644
--- a/products/posthog_ai/frontend/components/ActivityPrimitives.tsx
+++ b/products/posthog_ai/frontend/components/ActivityPrimitives.tsx
@@ -112,7 +112,10 @@ export function ActivityHeader({
return (
<div
className={clsx(
- 'group/activity-header transition-all duration-500 flex select-none min-w-0',
+ // Explicit transition properties, not transition-all: `all` also catches inherited
+ // scrollbar-color flips from the scrolling ancestor, starting hundreds of no-op
+ // transitions (and full-document style recalcs) whenever the thread is hovered.
+ 'group/activity-header transition-colors duration-500 flex select-none min-w-0',
isPending && 'text-muted',
isFailed && 'text-danger',
!isInProgress && !isPending && !isFailed && 'text-default',
@@ -140,7 +143,7 @@ export function ActivityHeader({
<div className="relative flex items-center justify-center size-5 shrink-0 overflow-hidden">
<span
className={clsx(
- 'inline-flex transition-all duration-200 ease-out',
+ 'inline-flex transition-[color,transform,opacity] duration-200 ease-out',
isInProgress && 'text-muted',
hasDetails &&
'group-hover/activity-header:-translate-x-1 group-hover/activity-header:scale-90 group-hover/activity-header:opacity-0 group-focus-within/activity-header:-translate-x-1 group-focus-within/activity-header:scale-90 group-focus-within/activity-header:opacity-0'
@@ -149,7 +152,7 @@ export function ActivityHeader({
{isInProgress && animate ? <ShimmeringContent>{icon}</ShimmeringContent> : icon}
</span>
{hasDetails && (
- <span className="absolute inline-flex translate-x-1 scale-90 text-tertiary opacity-0 transition-all duration-200 ease-out group-hover/activity-header:translate-x-0 group-hover/activity-header:scale-100 group-hover/activity-header:text-primary group-hover/activity-header:opacity-100 group-focus-within/activity-header:translate-x-0 group-focus-within/activity-header:scale-100 group-focus-within/activity-header:text-primary group-focus-within/activity-header:opacity-100">
+ <span className="absolute inline-flex translate-x-1 scale-90 text-tertiary opacity-0 transition-[color,transform,opacity] duration-200 ease-out group-hover/activity-header:translate-x-0 group-hover/activity-header:scale-100 group-hover/activity-header:text-primary group-hover/activity-header:opacity-100 group-focus-within/activity-header:translate-x-0 group-focus-within/activity-header:scale-100 group-focus-within/activity-header:text-primary group-focus-within/activity-header:opacity-100">
<IconChevronDown className="size-5" />
</span>
)}
@@ -296,7 +299,7 @@ export function Activity({
}, [shouldExpandDetails])
return (
- <div className="flex flex-col rounded transition-all duration-500 w-full min-w-0 gap-1 text-xs">
+ <div className="flex flex-col rounded w-full min-w-0 gap-1 text-xs">
<ActivityHeader
title={title}
status={status}
diff --git a/products/posthog_ai/frontend/components/AutosizeTextArea.scss b/products/posthog_ai/frontend/components/AutosizeTextArea.scss
new file mode 100644
index 000000000000..a9c1ca4abb71
--- /dev/null
+++ b/products/posthog_ai/frontend/components/AutosizeTextArea.scss
@@ -0,0 +1,31 @@
+.AutosizeTextArea {
+ display: block;
+ width: 100%;
+ min-height: 2.5rem;
+ padding: 0.5rem;
+ font-size: 0.875rem;
+ line-height: 1.4;
+ color: var(--text-3000);
+ text-align: left;
+ text-overflow: ellipsis;
+ cursor: text;
+ resize: none;
+ background: none;
+ background-color: var(--color-bg-fill-input);
+ outline: none;
+ box-shadow: none;
+
+ &:disabled {
+ cursor: not-allowed;
+ opacity: var(--opacity-disabled);
+ }
+}
+
+// Native autosizing where supported. The 1rem term is the vertical padding (0.5rem × 2);
+// rows are clamped via min/max-height since field-sizing ignores the `rows` attribute.
+.AutosizeTextArea--native {
+ /* stylelint-disable-next-line property-no-unknown -- field-sizing is a valid CSS property */
+ field-sizing: content;
+ min-height: max(2.5rem, calc(var(--autosize-textarea-min-rows, 1) * 1lh + 1rem));
+ max-height: calc(var(--autosize-textarea-max-rows, 1000) * 1lh + 1rem);
+}
diff --git a/products/posthog_ai/frontend/components/AutosizeTextArea.tsx b/products/posthog_ai/frontend/components/AutosizeTextArea.tsx
new file mode 100644
index 000000000000..7511304dec2e
--- /dev/null
+++ b/products/posthog_ai/frontend/components/AutosizeTextArea.tsx
@@ -0,0 +1,111 @@
+import './AutosizeTextArea.scss'
+
+import React, { useRef } from 'react'
+import TextareaAutosize from 'react-textarea-autosize'
+
+import { cn } from 'lib/utils/css-classes'
+
+// Native CSS autosizing where supported. The JS fallback (react-textarea-autosize) calls
+// getComputedStyle on every keystroke, which forces a synchronous whole-document style recalc —
+// hundreds of ms on threads with lots of mounted content.
+const SUPPORTS_FIELD_SIZING =
+ typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('field-sizing', 'content')
+
+export interface AutosizeTextAreaProps extends Pick<
+ React.TextareaHTMLAttributes<HTMLTextAreaElement>,
+ 'id' | 'placeholder' | 'disabled' | 'maxLength' | 'onFocus' | 'onBlur' | 'onKeyDown' | 'aria-describedby'
+> {
+ value?: string
+ onChange?: (newValue: string) => void
+ /** Called when Enter is pressed without Shift (Shift+Enter inserts a newline). */
+ onPressEnter?: (currentValue: string) => void
+ /** Called when Cmd/Ctrl+Enter is pressed (plain Enter inserts a newline). */
+ onPressCmdEnter?: (currentValue: string) => void
+ minRows?: number
+ maxRows?: number
+ autoFocus?: boolean
+ /** Classes for the wrapper element around the textarea. */
+ className?: string
+ /**
+ * Classes for the `<textarea>` itself. Padding utilities belong here (not on the wrapper), so the
+ * text is inset while the scrollbar still renders at the textarea's true edge.
+ */
+ textareaClassName?: string
+ /** Skip the `input-like` border/focus frame around the textarea. */
+ hideFocus?: boolean
+ 'data-attr'?: string
+}
+
+/** A self-sizing `textarea` for the agent composer surfaces. */
+export const AutosizeTextArea = React.forwardRef<HTMLTextAreaElement, AutosizeTextAreaProps>(function AutosizeTextArea(
+ {
+ className,
+ textareaClassName,
+ onChange,
+ onPressEnter,
+ onPressCmdEnter,
+ minRows = 1,
+ maxRows,
+ onKeyDown,
+ autoFocus,
+ hideFocus = false,
+ ...textProps
+ },
+ ref
+): JSX.Element {
+ const _ref = useRef<HTMLTextAreaElement | null>(null)
+ const textRef = ref || _ref
+
+ const textareaClasses = cn('AutosizeTextArea w-full rounded', textareaClassName)
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>): void => {
+ if (e.key === 'Enter' && !e.nativeEvent.isComposing) {
+ const target = e.currentTarget
+ // When shift is pressed, we always just want to add a new line
+ if (!e.shiftKey) {
+ if ((e.metaKey || e.ctrlKey) && onPressCmdEnter) {
+ onPressCmdEnter(target.value)
+ e.preventDefault()
+ } else if (onPressEnter) {
+ onPressEnter(target.value)
+ e.preventDefault()
+ }
+ }
+ }
+ onKeyDown?.(e)
+ }
+ const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>): void => {
+ onChange?.(event.currentTarget.value ?? '')
+ }
+
+ return (
+ <div className={cn('flex flex-col rounded', !hideFocus && 'input-like', className)}>
+ {SUPPORTS_FIELD_SIZING ? (
+ <textarea
+ ref={textRef}
+ className={cn('AutosizeTextArea--native', textareaClasses)}
+ style={
+ {
+ '--autosize-textarea-min-rows': minRows,
+ '--autosize-textarea-max-rows': maxRows,
+ } as React.CSSProperties
+ }
+ onKeyDown={handleKeyDown}
+ onChange={handleChange}
+ autoFocus={!!autoFocus}
+ {...textProps}
+ />
+ ) : (
+ <TextareaAutosize
+ minRows={minRows}
+ maxRows={maxRows}
+ ref={textRef}
+ className={textareaClasses}
+ onKeyDown={handleKeyDown}
+ onChange={handleChange}
+ autoFocus={!!autoFocus}
+ {...textProps}
+ />
+ )}
+ </div>
+ )
+})
diff --git a/products/posthog_ai/frontend/components/QueuedMessageList.tsx b/products/posthog_ai/frontend/components/QueuedMessageList.tsx
index c2359f47140a..ea5e9f02f2e7 100644
--- a/products/posthog_ai/frontend/components/QueuedMessageList.tsx
+++ b/products/posthog_ai/frontend/components/QueuedMessageList.tsx
@@ -1,9 +1,10 @@
import { useEffect, useRef, useState } from 'react'
import { IconCheck, IconPencil, IconTrash, IconX } from '@posthog/icons'
-import { LemonButton, LemonTextArea } from '@posthog/lemon-ui'
+import { LemonButton } from '@posthog/lemon-ui'
import type { QueuedMessage } from '../logics/runInteractionLogic'
+import { AutosizeTextArea } from './AutosizeTextArea'
export interface QueuedMessageListProps {
messages: QueuedMessage[]
@@ -48,7 +49,7 @@ function QueuedMessageItem({
if (isEditing) {
return (
<div className="space-y-2">
- <LemonTextArea
+ <AutosizeTextArea
ref={textAreaRef}
value={draft}
onChange={setDraft}
diff --git a/products/posthog_ai/frontend/components/composer/Composer.stories.tsx b/products/posthog_ai/frontend/components/composer/Composer.stories.tsx
index e9e0f59e69d9..99188807f805 100644
--- a/products/posthog_ai/frontend/components/composer/Composer.stories.tsx
+++ b/products/posthog_ai/frontend/components/composer/Composer.stories.tsx
@@ -36,7 +36,7 @@ const meta: Meta<ComposerStoryArgs> = {
render: ({ initialValue, placeholder, ...rootProps }) => {
const [value, setValue] = useState(initialValue)
return (
- <div className="max-w-180 mx-auto p-4">
+ <div className="w-180 mx-auto p-4">
<Composer.Root value={value} onChange={setValue} onSubmit={() => setValue('')} {...rootProps}>
<Composer.Frame>
<Composer.Field>
@@ -94,7 +94,7 @@ export const WithFooter: Story = {
render: ({ initialValue, placeholder, ...rootProps }) => {
const [value, setValue] = useState(initialValue)
return (
- <div className="max-w-180 mx-auto p-4">
+ <div className="w-180 mx-auto p-4">
<Composer.Root value={value} onChange={setValue} onSubmit={() => setValue('')} {...rootProps}>
<Composer.Frame>
<Composer.Field>
@@ -125,7 +125,7 @@ export const WithUpNextQueue: Story = {
{ id: '2', content: 'And add a comparison to the previous period' },
])
return (
- <div className="max-w-180 mx-auto p-4">
+ <div className="w-180 mx-auto p-4">
<Composer.Root value={value} onChange={setValue} onSubmit={() => setValue('')} {...rootProps}>
<Composer.Banner>
<QueuedMessageList
diff --git a/products/posthog_ai/frontend/components/composer/Composer.tsx b/products/posthog_ai/frontend/components/composer/Composer.tsx
index f4548a2ff20c..ef4abf2686e6 100644
--- a/products/posthog_ai/frontend/components/composer/Composer.tsx
+++ b/products/posthog_ai/frontend/components/composer/Composer.tsx
@@ -12,10 +12,12 @@ import {
} from 'react'
import { IconArrowRight, IconStopFilled } from '@posthog/icons'
-import { LemonButton, LemonTextArea } from '@posthog/lemon-ui'
+import { LemonButton } from '@posthog/lemon-ui'
import { cn } from 'lib/utils/css-classes'
+import { AutosizeTextArea } from '../AutosizeTextArea'
+
// Radix-style compound composer: a set of logic-free, presentational surfaces that reproduce the
// PostHog AI input look (see scenes/max/components/QuestionInput.tsx) without any of its conversation
// logic. `Composer.Root` owns nothing but the controlled value/submit plumbing it's handed; every
@@ -290,7 +292,7 @@ function ComposerTextarea({
}: ComposerTextareaProps): JSX.Element {
const { value, onChange, submit, textAreaRef, disabled, id } = useComposerContext()
return (
- <LemonTextArea
+ <AutosizeTextArea
id={id}
aria-describedby={!value ? `${id}-hint` : undefined}
ref={textAreaRef}
@@ -300,7 +302,8 @@ function ComposerTextarea({
minRows={minRows}
maxRows={maxRows}
autoFocus={autoFocus}
- className={cn('!border-none !bg-transparent min-h-16 py-2 pl-2 pr-12 resize-none', className)}
+ className={cn('py-2 pl-2', className)}
+ textareaClassName="!border-none !bg-transparent min-h-16 pr-12 resize-none"
hideFocus
onPressEnter={() => submit()}
{...rest}
diff --git a/products/posthog_ai/package.json b/products/posthog_ai/package.json
index 58d80781288d..45798502e23f 100644
--- a/products/posthog_ai/package.json
+++ b/products/posthog_ai/package.json
@@ -12,6 +12,7 @@
"monaco-editor": "^0.55.1",
"posthog-js": "catalog:",
"react-intersection-observer": "^9.5.3",
+ "react-textarea-autosize": "*",
"tailwind-merge": "*"
},
"devDependencies": {