Skip to content

[x-chat] Fix object URL leaks for submitted attachments#23198

Merged
hasdfa merged 3 commits into
mui:masterfrom
hasdfa:t3code/fix-x-chat-package-bug
Jul 23, 2026
Merged

[x-chat] Fix object URL leaks for submitted attachments#23198
hasdfa merged 3 commits into
mui:masterfrom
hasdfa:t3code/fix-x-chat-package-bug

Conversation

@hasdfa

@hasdfa hasdfa commented Jul 22, 2026

Copy link
Copy Markdown
Member

Changelog

Fix an object URL leak when submitting non-image attachments with @mui/x-chat-headless.

What changed

  • Track object URLs created while constructing outgoing non-image file parts.
  • Keep each URL alive while its stored message references it.
  • Revoke owned URLs when the message is removed or the composer unmounts.
  • Revoke partially created URLs if constructing a later file part throws.
  • Preserve the existing behavior where non-image draft attachments have no previewUrl.

Root cause

Image preview URLs were created when attachments entered the draft and were tracked through the draft and message lifecycles. Non-image URLs were instead created during submission and never registered with either ownership map, leaving no cleanup path.

Validation

  • Added regression coverage for message removal, composer unmount, and partial construction failure.

  • Confirmed all three tests fail against the original implementation and pass with the fix.

  • pnpm test:unit --project "x-chat-headless" --run — 640 passed, 24 skipped.

  • pnpm --filter "@mui/x-chat-headless" run typescript

  • pnpm eslint

  • pnpm prettier

  • I have followed (at least) the PR section of the contributing guide.

@code-infra-dashboard

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-23198--material-ui-x.netlify.app/
QR code for https://deploy-preview-23198--material-ui-x.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)
@mui/x-scheduler 0B(0.00%) 0B(0.00%)
@mui/x-scheduler-premium 0B(0.00%) 0B(0.00%)
@mui/x-chat 🔺+140B(+0.04%) 🔺+40B(+0.04%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@hasdfa hasdfa changed the title [x-chat] Fix submitted attachment object URL cleanup [x-chat] Fix object URL leaks for submitted attachments Jul 23, 2026
@hasdfa
hasdfa marked this pull request as ready for review July 23, 2026 09:50
Copilot AI review requested due to automatic review settings July 23, 2026 09:50

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@hasdfa

hasdfa commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

@codex review

@hasdfa hasdfa added type: bug It doesn't behave as expected. scope: chat Changes related to the AI chat. labels Jul 23, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: b23aad7995

ℹ️ 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".

@hasdfa
hasdfa merged commit 99b3a35 into mui:master Jul 23, 2026
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: chat Changes related to the AI chat. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants