Skip to content

refactor(web): extract composer text + draft persistence into a composable#1031

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

refactor(web): extract composer text + draft persistence into a composable#1031
wbxl2000 merged 1 commit into
mainfrom
refactor/web-extract-composer-draft

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 useInputHistory, #1026 useSlashMenu, #1030 useMentionMenu). This is the next Composer slice. No standalone issue.

Problem

Composer.vue is still large (~1987 lines after #1030). The composer's core text state (text, textareaRef, autosize) and its per-session unsent-draft persistence (the loadDraft/saveDraft helpers and the text→save and sessionId→load watchers) lived inline at the top of the component. These refs are shared with the history / slash / mention composables, so consolidating them is the natural next slice.

What changed

  • New apps/kimi-web/src/composables/useComposerDraft.ts:
    • Owns the text and textareaRef refs, the autosize helper, the loadDraft/saveDraft storage helpers, the two draft watchers, and the loadForEdit handle.
    • Takes { sessionId: () => string | undefined } as a dep (getter so the session-switch watcher stays reactive).
    • Returns { text, textareaRef, autosize, loadForEdit }.
  • Composer.vue:
    • Replaces the inline textarea/draft section and the inline loadForEdit with a single useComposerDraft({ sessionId: () => props.sessionId }) call.
    • The returned text / textareaRef / autosize are passed straight through to useInputHistory / useSlashMenu / useMentionMenu as their deps; loadForEdit is still defineExpose'd. The rest of the component is unchanged.
    • 1987 → 1937 lines.
  • Added test/composer-draft.test.ts (6 cases: load stored draft on init, empty when none, persist on change, clear on empty, save-old/load-new on session switch, loadForEdit).

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 — 76 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/composer-draft.test.ts.)
  • Ran gen-changesets skill, or this PR needs no changeset. (Added .changeset/web-extract-composer-draft.md, patch on @moonshot-ai/kimi-code.)
  • Ran gen-docs skill, or this PR needs no doc update. (No user-facing change.)

…sable

Move the composer's text ref, textarea ref, autosize helper, the per-session
draft load/save watchers, and the loadForEdit handle into useComposerDraft.
The returned text/textareaRef/autosize refs are passed straight through to the
history / slash / mention composables as their deps, so the rest of the
component is unchanged.

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

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c580add

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@c580add
npx https://pkg.pr.new/@moonshot-ai/kimi-code@c580add

commit: c580add

@wbxl2000 wbxl2000 merged commit 2bfd686 into main Jun 23, 2026
9 checks passed
@wbxl2000 wbxl2000 deleted the refactor/web-extract-composer-draft branch June 23, 2026 11:14
@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