Skip to content

fix(attachment): reclaim applied previews on unmount - #601

Open
IzumiSy wants to merge 3 commits into
mainfrom
fix/attachment-preview-url-cleanup
Open

IzumiSy wants to merge 3 commits into
mainfrom
fix/attachment-preview-url-cleanup

Conversation

@IzumiSy

@IzumiSy IzumiSy commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Motivation

useAttachment retains image previews after a successful applyChanges() call, but clears the corresponding buffered upload operations. Its unmount cleanup previously read only that operation buffer, so successfully applied images no longer had their Blob URLs reclaimed when the hook unmounted.

This extracts the Attachment cleanup from #525 into an independent, small bug-fix PR based on main. It does not depend on the test-cleanup PR or include the lint upgrade and other state-ownership changes.

Design Decision

Track preview lifetime separately from pending operations

Keep a registry of Blob URLs created by this hook. Successful applies leave the previews usable, deletion releases and removes a URL, and unmount releases the remaining registered URLs. Caller-supplied initial URLs are not registered for unmount cleanup.

The existing operation buffering, rollback, and concurrent-flush behavior remain unchanged. No public API changes are needed.

Summary

  • Reclaim image preview URLs on unmount even after their upload operations have been successfully applied.
  • Cover pending/applied previews, caller-supplied URLs, and avoiding a second release of deleted previews.
  • Add a patch changeset for the resource leak fix.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Code Metrics Report

main (589a66f) #601 (2a32049) +/-
Coverage 88.7% 88.7% +0.0%
Test Execution Time 2m21s 2m14s -7s
Details
  |                     | main (589a66f) | #601 (2a32049) |  +/-  |
  |---------------------|----------------|----------------|-------|
+ | Coverage            |          88.7% |          88.7% | +0.0% |
  |   Files             |            208 |            208 |     0 |
  |   Lines             |           6282 |           6284 |    +2 |
+ |   Covered           |           5574 |           5576 |    +2 |
+ | Test Execution Time |          2m21s |          2m14s |   -7s |

Code coverage of files in pull request scope (100.0% → 100.0%, patch 100.0%)

Files Coverage +/- Patch Coverage Status
packages/core/src/components/attachment/use-attachment.ts 100.0% 0.0% 100.0% modified

Reported by octocov

@IzumiSy
IzumiSy marked this pull request as ready for review October 13, 2026 03:56
@IzumiSy
IzumiSy requested a review from a team as a code owner October 13, 2026 03:56
@IzumiSy

IzumiSy commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Code Review completed successfully!

Code review complete for PR #601 - no actionable High/Medium issues found in changed packages/core attachment hook behavior, and this workflow does not expose a general PR comment tool for approval-only reviews.

Generated by Code Review for #601

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.

🟢 Approval recommended

The ownership-based cleanup is correct, narrowly scoped, and covered by relevant lifecycle tests.

0 open findings

What changed in this PR

Fixes Blob URL leaks by tracking attachment previews independently from buffered operations.

Changes:

  • Reclaims pending and applied previews on unmount.
  • Prevents double revocation after deletion.
  • Adds regression tests and a patch changeset.
File Description
use-attachment.ts Tracks and releases hook-owned preview URLs.
use-attachment.test.ts Tests cleanup across apply, delete, and unmount.
.changeset/​tidy-otters-rest.md Documents the patch release.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

3 participants