Extract shared useStartupAttachments hook - #876
Merged
Conversation
The startup-attachment state and callbacks (file dedupe + object-URL previews, add/remove file and link handlers, drop handler, and the revoke-on-unmount effect) were duplicated between use-create-agent-form and the template launch dialog. Move them into a single useStartupAttachments hook consumed by both. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extracts the duplicated startup-attachment logic in
use-create-agent-form.tsandautomations-launch-dialog.tsxinto a singleuseStartupAttachments()hook (apps/web/src/components/app/use-startup-attachments.ts), consumed by both.The duplicated surface was: the
startupFiles/startupLinks/draggingFilesstate trio, the object-URL previews ref,appendStartupFiles(dedupe bystartupFileKey+ create object URLs for images),handleAddLink,handleRemoveStartupFile(revokes the preview URL),handleRemoveStartupLink, the drop handler, and the revoke-all-previews-on-unmount effect — ~85 lines mirrored byte-for-byte across the two files. Net −30 lines; no behavior change.Why it qualifies as tech debt
Two byte-identical copies of object-URL lifecycle code is exactly the kind of duplication that drifts: a leak fix or dedupe change in one dialog would silently miss the other. Backlog item from the 2026-07-21 audit (tech-debt Brain).
Validation
pnpm run check,pnpm run finalize:webgreenuse-create-agent-form.test.tsx(25 tests, covers dedupe/preview/revoke through the hook) greenpnpm run test:e2e: 175 passednaturalWidth > 0), remove → preview revoked, re-add → fresh blob URL renders (screenshots shared via dispatch media)Queued next
Top of the tech-debt backlog: extract the duplicated job schedule field block (
jobs-add-dialog.tsxvsjobs-settings-tab.tsx) into a<JobScheduleField>component.🤖 Generated with Claude Code