Skip to content

refactor(web): extract attachment upload into a composable#1034

Merged
wbxl2000 merged 1 commit into
mainfrom
refactor/web-extract-attachment-upload
Jun 23, 2026
Merged

refactor(web): extract attachment upload into a composable#1034
wbxl2000 merged 1 commit into
mainfrom
refactor/web-extract-attachment-upload

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

Related Issue

Part of the apps/kimi-web god-component split tracked in web-refactor-plan.md (follows #1011, #1026, #1030, #1031). This is the final Composer slice. No standalone issue.

Problem

Composer.vue was the largest component in the web app (~1937 lines after #1031). The image/video attachment handling — the chip strip, the file picker, paste, drag & drop, the upload machinery, and the preview lightbox — is a cohesive feature that lived inline in the composer, intertwined with the draft, the slash/mention menus, and the keydown orchestration.

What changed

  • New apps/kimi-web/src/composables/useAttachmentUpload.ts:
    • Owns the attachments / previewAttachment / fileInputRef / isDragOver state, the Attachment type, the file-picker / paste / drag-drop handlers, the addFiles upload machinery, and the clearAfterSubmit() helper.
    • Owns its own lifecycle: registers the global paste listener on mount and revokes all object URLs + removes the listener on unmount.
    • Takes { uploadImage: () => ... } as a dep.
  • Composer.vue:
    • Replaces the inline attachment block (~140 lines) and the Attachment interface with a single useAttachmentUpload({ uploadImage: () => props.uploadImage }) call, destructured back to the original names so the template bindings (chip strip, lightbox, file input, drag handlers) are unchanged.
    • handleSubmit / handleSteer now call clearAfterSubmit() to revoke object URLs and drop the list, instead of the inline revoke loop.
    • The composer's onMounted / onUnmounted no longer touch the paste listener or attachment cleanup (the composable owns those).
    • 1937 → 1787 lines.
  • Added test/attachment-upload.test.ts (7 cases: file-input add, non-media ignore, no-op without uploadImage, remove + revoke, remove closing the preview, preview open/close, clearAfterSubmit).

No user-visible behavior change. Logic moved verbatim; only the call sites were re-wired.

Verification

  • pnpm --filter @moonshot-ai/kimi-web typecheck — pass (vue-tsc --noEmit)
  • pnpm --filter @moonshot-ai/kimi-web test — 83 passed
  • pnpm --filter @moonshot-ai/kimi-web build — pass
  • oxlint --type-aware on the changed files — 0 warnings, 0 errors

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works. (test/attachment-upload.test.ts.)
  • Ran gen-changesets skill, or this PR needs no changeset. (Added .changeset/web-extract-attachment-upload.md, patch on @moonshot-ai/kimi-code.)
  • Ran gen-docs skill, or this PR needs no doc update. (No user-facing change.)

Move the image/video attachment state, the file-picker / paste / drag-drop
handlers, the upload machinery, the preview lightbox, and the paste-listener
+ object-URL cleanup lifecycle out of Composer into useAttachmentUpload.

The composer keeps handleSubmit / handleSteer (which read the attachments to
build the payload) and the hasUpload toolbar flag; it consumes the returned
refs and handlers directly. The destructured names match the originals so the
template bindings are unchanged. handleSubmit / handleSteer now call the
composable's clearAfterSubmit() to revoke object URLs and drop the list.

Composer.vue: 1937 -> 1787 lines. Adds unit tests for useAttachmentUpload. No
behavior change.
@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7dd86fa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 23, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@7dd86fa
npx https://pkg.pr.new/@moonshot-ai/kimi-code@7dd86fa

commit: 7dd86fa

@wbxl2000 wbxl2000 merged commit 603a767 into main Jun 23, 2026
9 checks passed
@wbxl2000 wbxl2000 deleted the refactor/web-extract-attachment-upload branch June 23, 2026 11:52
@github-actions github-actions Bot mentioned this pull request Jun 23, 2026
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