This repository was archived by the owner on Aug 6, 2026. It is now read-only.
Repository navigation
fix(channels): render prompt expansion inline #3732
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -422,42 +422,80 @@ function ExpandablePrompt({ | |||||||||
| }) { | ||||||||||
| const observerRef = useRef<ResizeObserver | null>(null); | ||||||||||
| const [expanded, setExpanded] = useState(false); | ||||||||||
| const [truncated, setTruncated] = useState(false); | ||||||||||
| const [truncatedText, setTruncatedText] = useState<string | null>(null); | ||||||||||
| const measureTextRef = useRef<HTMLSpanElement>(null); | ||||||||||
| const measureMoreRef = useRef<HTMLSpanElement>(null); | ||||||||||
| const collapsedText = children.replace(/\s+/g, " ").trim(); | ||||||||||
|
|
||||||||||
| const measureRef = useCallback( | ||||||||||
| (body: HTMLDivElement | null) => { | ||||||||||
| observerRef.current?.disconnect(); | ||||||||||
| observerRef.current = null; | ||||||||||
| if (!body || expanded) return; | ||||||||||
| const measure = () => setTruncated(body.scrollHeight > body.clientHeight); | ||||||||||
| const measure = () => { | ||||||||||
| const text = measureTextRef.current; | ||||||||||
| const more = measureMoreRef.current; | ||||||||||
| if (!text || !more) return; | ||||||||||
|
|
||||||||||
| more.hidden = true; | ||||||||||
| text.textContent = collapsedText; | ||||||||||
| if (body.scrollHeight <= body.clientHeight) { | ||||||||||
| setTruncatedText(null); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| more.hidden = false; | ||||||||||
| let low = 0; | ||||||||||
| let high = collapsedText.length; | ||||||||||
| while (low < high) { | ||||||||||
| const middle = Math.ceil((low + high) / 2); | ||||||||||
| text.textContent = `${collapsedText.slice(0, middle).trimEnd()}... `; | ||||||||||
| if (body.scrollHeight <= body.clientHeight) { | ||||||||||
| low = middle; | ||||||||||
| } else { | ||||||||||
| high = middle - 1; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| setTruncatedText(collapsedText.slice(0, low).trimEnd()); | ||||||||||
| }; | ||||||||||
| measure(); | ||||||||||
| const observer = new ResizeObserver(measure); | ||||||||||
| observer.observe(body); | ||||||||||
| observer.observe(body.parentElement ?? body); | ||||||||||
| observerRef.current = observer; | ||||||||||
| }, | ||||||||||
| [expanded], | ||||||||||
| [collapsedText, expanded], | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| return ( | ||||||||||
| <div> | ||||||||||
| <ThreadItemBody | ||||||||||
| ref={measureRef} | ||||||||||
| className={cn( | ||||||||||
| "wrap-break-word whitespace-pre-wrap", | ||||||||||
| !expanded && (lines === 2 ? "line-clamp-2" : "line-clamp-4"), | ||||||||||
| <div className="relative"> | ||||||||||
| <ThreadItemBody className="wrap-break-word whitespace-pre-wrap"> | ||||||||||
| {expanded || truncatedText === null ? children : truncatedText} | ||||||||||
| {truncatedText !== null && !expanded && "... "} | ||||||||||
| {truncatedText !== null && ( | ||||||||||
|
Comment on lines
+473
to
+474
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The expanded branch renders the original prompt directly beside the
Suggested change
Rule Used: Maintain proper spacing in template strings. Ensur... (source) Learned From Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/ui/src/features/canvas/components/ChannelFeedView.tsx
Line: 473-474
Comment:
**Expanded Action Joins Final Word**
The expanded branch renders the original prompt directly beside the `less` button. When the prompt does not end with whitespace, users see text such as `final wordless` instead of a separated inline action.
```suggestion
{truncatedText !== null && (expanded ? " " : "... ")}
{truncatedText !== null && (
```
**Rule Used:** Maintain proper spacing in template strings. Ensur... ([source](https://app.greptile.com/posthog-org-19734/-/custom-context?memory=d0a97985-7ddb-464d-9739-625899016a97))
**Learned From**
[PostHog/posthog#32603](https://github.com/PostHog/posthog/pull/32603)
How can I resolve this? If you propose a fix, please make it concise.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! |
||||||||||
| <button | ||||||||||
| type="button" | ||||||||||
| aria-expanded={expanded} | ||||||||||
| className="text-muted-foreground text-xs underline underline-offset-2 hover:text-foreground" | ||||||||||
| onClick={() => setExpanded((value) => !value)} | ||||||||||
| > | ||||||||||
| {expanded ? "less" : "more"} | ||||||||||
| </button> | ||||||||||
| )} | ||||||||||
| > | ||||||||||
| {children} | ||||||||||
| </ThreadItemBody> | ||||||||||
| {(truncated || expanded) && ( | ||||||||||
| <button | ||||||||||
| type="button" | ||||||||||
| aria-expanded={expanded} | ||||||||||
| className="text-muted-foreground text-xs underline underline-offset-2 hover:text-foreground" | ||||||||||
| onClick={() => setExpanded((value) => !value)} | ||||||||||
| {!expanded && ( | ||||||||||
| <ThreadItemBody | ||||||||||
| ref={measureRef} | ||||||||||
| aria-hidden="true" | ||||||||||
| className={cn( | ||||||||||
| "wrap-break-word pointer-events-none invisible absolute inset-x-0 top-0 whitespace-normal", | ||||||||||
| lines === 2 ? "line-clamp-2" : "line-clamp-4", | ||||||||||
| )} | ||||||||||
| > | ||||||||||
| {expanded ? "less" : "more"} | ||||||||||
| </button> | ||||||||||
| <span ref={measureTextRef}>{collapsedText}</span> | ||||||||||
| <span ref={measureMoreRef} className="text-xs"> | ||||||||||
| more | ||||||||||
| </span> | ||||||||||
| </ThreadItemBody> | ||||||||||
| )} | ||||||||||
| </div> | ||||||||||
| ); | ||||||||||
|
|
||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The search slices by UTF-16 code units. When the fitting boundary lands inside a supplementary character such as an emoji, the collapsed prompt renders a replacement glyph before the ellipsis.
Prompt To Fix With AI
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!