Skip to content

fix(queued-messages): clamp long queued messages to 3 lines#3163

Open
harshjainnn wants to merge 1 commit into
PostHog:mainfrom
harshjainnn:fix/clamp-long-queued-messages
Open

fix(queued-messages): clamp long queued messages to 3 lines#3163
harshjainnn wants to merge 1 commit into
PostHog:mainfrom
harshjainnn:fix/clamp-long-queued-messages

Conversation

@harshjainnn

Copy link
Copy Markdown

Long queued messages (e.g. a pasted code block) previously rendered at full height, and this compounded with multiple queued messages, pushing the composer off-screen. Clamp to 3 lines with a fade mask and a 'Show more/less' toggle, mirroring the clamp pattern already used for sent messages in ChatThread's UserBubble.

Fixes #3150

Problem

Queued follow-up messages render at full height with no clamp. A long queued message (e.g. a pasted code block) can grow the dock to hundreds of pixels tall, and this compounds when multiple long messages are queued at once — pushing the composer off-screen.

Changes

Clamped QueuedMessageView content to 3 lines by default, with a bottom fade mask and a "Show more/less" toggle that only appears when the content actually overflows the clamp. This mirrors the existing clamp-by-measured-height pattern used in ChatThread.tsx's UserBubble for sent messages — a ResizeObserver compares scrollHeight against the clamped clientHeight, since overflow can't be determined from character count alone (it depends on wrap width).

Also changed the outer row's alignment from align="center" to align="start" so the icon and action buttons (Steer/Edit/Discard) stay pinned to the top when content spans multiple lines, instead of being vertically centered against a tall block.

How did you test this?

  • Queued several short messages — dock renders unchanged, no toggle appears.
  • Queued a message containing a long code block — content clamps to 3 lines with a fade, "Show more" expands it, "Show less" re-collapses it.
  • Queued a mix of short and long messages together — short ones render untouched, long ones clamp independently of each other.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Long queued messages (e.g. a pasted code block) previously rendered at full height, and this compounded with multiple queued messages, pushing the composer off-screen. Clamp to 3 lines with a fade mask and a 'Show more/less' toggle, mirroring the clamp pattern already used for sent messages in ChatThread's UserBubble.

Fixes PostHog#3150
@trunk-io

trunk-io Bot commented Jul 6, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@harshjainnn

Copy link
Copy Markdown
Author

/trunk merge

@trunk-io

trunk-io Bot commented Jul 6, 2026

Copy link
Copy Markdown

An error occurred while submitting your PR to the queue: Only users that are a part of this repo's Trunk organization or have write permissions to the repo can submit a PR to the queue

@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(queued-messages): clamp long queued ..." | Re-trigger Greptile

Comment on lines +34 to +51
const [isExpanded, setIsExpanded] = useState(false);
const [isOverflowing, setIsOverflowing] = useState(false);
const textRef = useRef<HTMLDivElement>(null);

// Only meaningful while collapsed: expanding removes the clamp so scrollHeight === clientHeight.
// We keep the prior result when expanded so the "Show less" trigger stays put.
// biome-ignore lint/correctness/useExhaustiveDependencies: re-measure when the message text changes.
useLayoutEffect(() => {
if (isExpanded) return;
const el = textRef.current;
if (!el) return;
const measure = () =>
setIsOverflowing(el.scrollHeight - el.clientHeight > 1);
measure();
const observer = new ResizeObserver(measure);
observer.observe(el);
return () => observer.disconnect();
}, [message.content, isExpanded]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Duplicated expand/clamp logic — consider extracting a hook

The isExpanded/isOverflowing/ResizeObserver pattern introduced here is near-identical to the one already present in ChatThread.tsx's UserBubble (lines 298–315), and a simpler variant exists in UserMessage.tsx too. This is now the third copy. Extracting a useOverflowClamp(contentRef, dep) hook would satisfy the OnceAndOnlyOnce rule, make the threshold (3lh vs 5lh) a parameter, and give one place to fix the missing aria-expanded on the toggle button that all three share.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +74 to +78
<button
type="button"
onClick={() => setIsExpanded((v) => !v)}
className="mt-1 flex items-center gap-0.5 text-muted-foreground text-xs hover:text-foreground"
>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The toggle button is missing aria-expanded, which is the standard accessibility attribute for disclosure widgets. Without it, screen readers can't announce the current collapsed/expanded state to users. The same omission exists in the original ChatThread.tsx UserBubble, but since this PR introduces the toggle in a new location it's worth fixing here.

Suggested change
<button
type="button"
onClick={() => setIsExpanded((v) => !v)}
className="mt-1 flex items-center gap-0.5 text-muted-foreground text-xs hover:text-foreground"
>
<button
type="button"
aria-expanded={isExpanded}
onClick={() => setIsExpanded((v) => !v)}
className="mt-1 flex items-center gap-0.5 text-muted-foreground text-xs hover:text-foreground"
>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

we probably need a way of visually shortening multiple long queued messages

1 participant