Skip to content

Read a chip label from the link text on formatted links - #354

Merged
abhishekgahlot2 merged 2 commits into
useagenthq:mainfrom
ElectLive:fix/markdown-chip-label-from-link-text
Nov 6, 2026
Merged

abhishekgahlot2 merged 2 commits into
useagenthq:mainfrom
ElectLive:fix/markdown-chip-label-from-link-text

Conversation

@ElectLive

@ElectLive ElectLive commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What is wrong

AnchorComponent built the artifact chip label by stringifying the link's React children:

const label =
  typeof children === "string"
    ? children
    : Array.isArray(children)
      ? children.join("")
      : "Open";

children.join("") turns a React element into "[object Object]", and when the link text is a single wrapped run (bold, inline code) neither branch matches and the label falls back to "Open". The label also feeds the round badge initial (line 320), so the badge showed the first character of the broken string. Rendering the real component at 01d1f32f gives:

Markdown badge chip label
[**Quarterly** report](https://example.com/report.pdf) [ [object Object] report
[`data.csv`](https://example.com/data.csv) O Open

The change

linkLabelText walks the rendered children to their plain text instead of stringifying them: text runs are joined, a line break reads as a space, and an image with no text of its own reads as its alt text. "Open" stays as the fallback for a link that genuinely carries no readable text, so that case is unchanged.

After the change the same three renders give initial="Q" label="Quarterly report", initial="D" label="data.csv" and initial="P" label="plain.pdf" (a plain text link was already correct and stays correct).

Only frontend/components/prompt-kit/markdown.tsx and frontend/components/prompt-kit/markdown.test.tsx change.

Verification

Run in frontend/ with bun 1.4.3 on Windows. The three new cases are red before the fix and green after.

bun test components/prompt-kit

(pass) Markdown links > reads a typed chip label from a formatted link text
(pass) Markdown links > keeps a link label when it is an image or spans lines
(pass) Markdown links > falls back to Open when a link carries no readable text
 23 pass
 0 fail
 162 expect() calls
Ran 23 tests across 2 files. [315.00ms]

bun test components app lib

 1692 pass
 4 fail
Ran 1696 tests across 259 files.

The same 4 tests fail on main in this checkout without the change (1689 pass, 4 fail), so they are pre-existing and unrelated: app/server-boundary.test.ts "re-exports up to two levels...", components/chat/session-rail-layout.test.ts (2 cases) and components/chat/terminal-surface.test.ts "fresh parser instances do not inherit disposed terminal cells". I did not touch those areas.

bun run typecheck -> exits 0
bun run lint -> exits 0, Checked 958 files, Found 248 warnings (all pre-existing repo-wide, none added in these files)
USEAGENT_API_ORIGIN=https://app.useagent.org bun run build -> exits 0, all routes compiled
bun test scripts/agent-docs.test.ts (repo root) -> 5 pass, 0 fail

What I did not do

I did not run this against app.useagent.org, because I have no account there and did not want to create one for a pull request. The proof above is the component's real server-rendered output (renderToStaticMarkup of <Markdown> from this repo) plus the check the issue asks for, bun test components/prompt-kit. If a screenshot in the running app is required before this can be reviewed, tell me what to click and I will take one.

Closes #337


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

The artifact chip label was built with children.join(""), so a link whose
text holds bold or inline code rendered "[object Object] report", and a link
whose text is a single wrapped run fell back to "Open". Both the label and
the badge initial came from that string, so [**Quarterly** report](x.pdf)
showed a "[" badge.

Walk the rendered children to their plain text instead, with a line break as
a space and an image as its alt text, and keep "Open" only as the fallback
for a link that carries no readable text.

Closes useagenthq#337
@abhishekgahlot2

Copy link
Copy Markdown
Contributor

recheck

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@ElectLive

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Oct 18, 2026
@abhishekgahlot2
abhishekgahlot2 merged commit 295dec0 into useagenthq:main Nov 6, 2026
21 checks passed
@abhishekgahlot2

Copy link
Copy Markdown
Contributor

Merged, thanks @ElectLive. Bold or code inside a link label no longer turns into "[object Object]", and the tests pin both cases.

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show the real link text on file chips that contain bold or code

2 participants