Skip to content

fix(channels): render prompt expansion inline#3732

Closed
adboio wants to merge 1 commit into
mainfrom
posthog-code/fix-inline-channel-prompt-truncation
Closed

fix(channels): render prompt expansion inline#3732
adboio wants to merge 1 commit into
mainfrom
posthog-code/fix-inline-channel-prompt-truncation

Conversation

@adboio

@adboio adboio commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Problem

Truncated channel prompts separated the ellipsis and expansion link from the text, especially when prompts contained newlines.

Why: Prompt previews should read as one continuous sentence with an obvious inline expansion action.

Changes

  • Measure the available lines and render the longest fitting prefix as text... more, with more in normal inline flow.
  • Normalize collapsed whitespace while preserving the original multiline content when expanded.

How did you test this?

  • pnpm --filter @posthog/ui exec vitest run src/features/canvas/components/ChannelFeedView.test.tsx
  • pnpm --filter @posthog/ui typecheck
  • Biome check on the changed files

Automatic notifications

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

Created with PostHog Code

Generated-By: PostHog Code
Task-Id: 8b5e328f-08da-4999-9414-071c743a9053
@trunk-io

trunk-io Bot commented Jul 22, 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

@github-actions

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 0ae996a.

@posthog

posthog Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

👋 Visual changes detected for this PR.

Review and approve in PostHog Visual Review

If these changes are unexpected, they may be caused by a flaky test or a broken snapshot on master. Don't approve — rerun the job or wait for a fix.

@adboio
adboio marked this pull request as ready for review July 22, 2026 22:50
@adboio adboio added the Stamphog This will request an autostamp by stamphog on small changes label Jul 22, 2026
@adboio adboio closed this Jul 22, 2026
@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
packages/ui/src/features/canvas/components/ChannelFeedView.tsx:448-459
**Unicode Boundary Corrupts Prompt Text**

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.

```suggestion
        const collapsedCharacters = Array.from(collapsedText);
        let low = 0;
        let high = collapsedCharacters.length;
        while (low < high) {
          const middle = Math.ceil((low + high) / 2);
          text.textContent = `${collapsedCharacters.slice(0, middle).join("").trimEnd()}... `;
          if (body.scrollHeight <= body.clientHeight) {
            low = middle;
          } else {
            high = middle - 1;
          }
        }
        setTruncatedText(
          collapsedCharacters.slice(0, low).join("").trimEnd(),
        );
```

### Issue 2 of 2
packages/ui/src/features/canvas/components/ChannelFeedView.tsx:473-474
**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 && (
```

Reviews (1): Last reviewed commit: "fix(channels): render prompt expansion i..." | Re-trigger Greptile

Comment on lines +448 to +459
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());

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.

P1 Unicode Boundary Corrupts Prompt Text

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.

Suggested change
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());
const collapsedCharacters = Array.from(collapsedText);
let low = 0;
let high = collapsedCharacters.length;
while (low < high) {
const middle = Math.ceil((low + high) / 2);
text.textContent = `${collapsedCharacters.slice(0, middle).join("").trimEnd()}... `;
if (body.scrollHeight <= body.clientHeight) {
low = middle;
} else {
high = middle - 1;
}
}
setTruncatedText(
collapsedCharacters.slice(0, low).join("").trimEnd(),
);
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/ui/src/features/canvas/components/ChannelFeedView.tsx
Line: 448-459

Comment:
**Unicode Boundary Corrupts Prompt Text**

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.

```suggestion
        const collapsedCharacters = Array.from(collapsedText);
        let low = 0;
        let high = collapsedCharacters.length;
        while (low < high) {
          const middle = Math.ceil((low + high) / 2);
          text.textContent = `${collapsedCharacters.slice(0, middle).join("").trimEnd()}... `;
          if (body.scrollHeight <= body.clientHeight) {
            low = middle;
          } else {
            high = middle - 1;
          }
        }
        setTruncatedText(
          collapsedCharacters.slice(0, low).join("").trimEnd(),
        );
```

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!

Comment on lines +473 to +474
{truncatedText !== null && !expanded && "... "}
{truncatedText !== null && (

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.

P1 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.

Suggested change
{truncatedText !== null && !expanded && "... "}
{truncatedText !== null && (
{truncatedText !== null && (expanded ? " " : "... ")}
{truncatedText !== null && (

Rule Used: Maintain proper spacing in template strings. Ensur... (source)

Learned From
PostHog/posthog#32603

Prompt To Fix With AI
This 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!

@stamphog

stamphog Bot commented Jul 22, 2026

Copy link
Copy Markdown

Note

🤖 stamphog reviewed 0ae996ad1cdc515c37bb376db0c4111c607f80fc — verdict: REFUSED

Greptile flagged two P1 correctness bugs (UTF-16 slicing can corrupt supplementary characters at the truncation boundary; the expanded view can visually merge the last word into the "less" button) and both are still present verbatim in the current diff — unresolved, not addressed by a later commit.

  • Author wrote 0% of the modified lines and has 10 merged PRs in these paths (familiarity MODERATE).
  • greptile-apps[bot] reviewed the current head.
  • Unresolved: ChannelFeedView.tsx truncation binary-search slices collapsedText by UTF-16 code units (line ~118), which can split a supplementary-plane character (e.g. an emoji) and render a replacement glyph — Greptile's suggested fix (Array.from over code points) was not applied.
  • Unresolved: in the expanded branch (line ~146-157), children is rendered directly followed by the less button with no separator, so text not ending in whitespace runs into the button label (e.g. "wordless") — Greptile's suggested spacing fix was not applied.
Gate mechanics and policy version
Gate Result
prerequisites all clear
deny-list no deny categories matched
size 78L, 1F substantive, 130L/2F incl. docs/generated/snapshots — within ceiling
tier T1-agent / T1c-medium (130L, 2F, single-area, fix)
stamphog 2.0.0b3 .stamphog/policy.yml @ f377ae9 · reviewed head 0ae996a

@stamphog stamphog Bot removed the Stamphog This will request an autostamp by stamphog on small changes label Jul 22, 2026
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.

1 participant