Skip to content

Extract shared useStartupAttachments hook - #876

Merged
selfcontained merged 1 commit into
mainfrom
tech-debt/startup-attachments-hook
Aug 4, 2026
Merged

Extract shared useStartupAttachments hook#876
selfcontained merged 1 commit into
mainfrom
tech-debt/startup-attachments-hook

Conversation

@selfcontained

Copy link
Copy Markdown
Owner

What

Extracts the duplicated startup-attachment logic in use-create-agent-form.ts and automations-launch-dialog.tsx into a single useStartupAttachments() hook (apps/web/src/components/app/use-startup-attachments.ts), consumed by both.

The duplicated surface was: the startupFiles/startupLinks/draggingFiles state trio, the object-URL previews ref, appendStartupFiles (dedupe by startupFileKey + 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:web green
  • use-create-agent-form.test.tsx (25 tests, covers dedupe/preview/revoke through the hook) green
  • pnpm run test:e2e: 175 passed
  • Live Playwright validation of the object-URL lifecycle in both dialogs on an isolated dev stack: attach image → blob preview renders (naturalWidth > 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.tsx vs jobs-settings-tab.tsx) into a <JobScheduleField> component.

🤖 Generated with Claude Code

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>
@selfcontained
selfcontained merged commit 700aeab into main Aug 4, 2026
1 check passed
@selfcontained
selfcontained deleted the tech-debt/startup-attachments-hook branch August 4, 2026 09:14
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.

1 participant