[chat] Normalize message part link URLs#23187
Conversation
Deploy previewhttps://deploy-preview-23187--material-ui-x.netlify.app/Bundle size
Check out the code infra dashboard for more information about this PR. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 12d72fd5b8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| <Root {...rootProps}> | ||
| <LinkSlot href={part.url} rel="noreferrer noopener" target="_blank" {...linkProps}> | ||
| <LinkSlot | ||
| href={safeUri(part.url) || undefined} |
There was a problem hiding this comment.
Preserve blob URLs for file parts
When a user sends an attachment, useChatComposer builds file parts with url: attachment.previewUrl ?? URL.createObjectURL(...) (packages/x-chat-headless/src/hooks/useChatComposer.ts:191-196), and the tests cover non-image blob:hello.txt attachments. safeUri only allows http/https/mailto/tel and relative URLs (partUtils.ts:34-40), so blob: is converted to '' here and the rendered anchor loses its href; sent text/PDF attachments become inert filenames instead of clickable/downloadable file links. The fallback renderDefaultFilePart has the same new call, so file parts should either allow safe blob: URLs or avoid applying this sanitizer to file attachment links.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 297b10b. File-part links now use a dedicated URL policy that preserves only same-origin blob URLs; cross-origin and opaque-origin blob URLs still render without an href. Source URL renderers keep the existing stricter policy. Added coverage for both FilePart renderers and the blob-origin checks, and verified the x-chat suites in jsdom and Chromium on React 18 and the current React version.
Changelog
Use the existing URI normalization helper for file and source link targets.
These renderers previously passed link targets directly instead of using the helper already available in
x-chat-headless. This keeps link handling consistent across the built-in component and fallback renderer paths, while preserving supported URLs as-is.Test plan
pnpm test:unit --project "x-chat-headless" --runpnpm test:browser --project "x-chat-headless" --run packages/x-chat-headless/src/message/parts/MessageParts.test.tsxpnpm --filter "@mui/x-chat-headless" run typescriptpnpm eslintI have followed (at least) the PR section of the contributing guide.