refactor(web): extract composer text + draft persistence into a composable#1031
Merged
Conversation
…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 detectedLatest commit: c580add The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
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.
Related Issue
Part of the
apps/kimi-webgod-component split tracked inweb-refactor-plan.md(follows #1011useInputHistory, #1026useSlashMenu, #1030useMentionMenu). This is the next Composer slice. No standalone issue.Problem
Composer.vueis still large (~1987 lines after #1030). The composer's core text state (text,textareaRef,autosize) and its per-session unsent-draft persistence (theloadDraft/saveDrafthelpers and thetext→save andsessionId→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
apps/kimi-web/src/composables/useComposerDraft.ts:textandtextareaRefrefs, theautosizehelper, theloadDraft/saveDraftstorage helpers, the two draft watchers, and theloadForEdithandle.{ sessionId: () => string | undefined }as a dep (getter so the session-switch watcher stays reactive).{ text, textareaRef, autosize, loadForEdit }.Composer.vue:loadForEditwith a singleuseComposerDraft({ sessionId: () => props.sessionId })call.text/textareaRef/autosizeare passed straight through touseInputHistory/useSlashMenu/useMentionMenuas their deps;loadForEditis stilldefineExpose'd. The rest of the component is unchanged.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 passedpnpm --filter @moonshot-ai/kimi-web build— passoxlint --type-awareon the changed files — 0 warnings, 0 errorsChecklist
test/composer-draft.test.ts.)gen-changesetsskill, or this PR needs no changeset. (Added.changeset/web-extract-composer-draft.md,patchon@moonshot-ai/kimi-code.)gen-docsskill, or this PR needs no doc update. (No user-facing change.)