refactor(web): composer context imports live in useComposerContextImport#23048
Context pasted or dropped into the composer goes through about 280 lines of import code in the composer body. That covers copied terminal output, review comments, annotations, threads, images and files, and the same code restores stash entries that carry records.
useComposerContextImport now holds that code:
runAttachmentImport, which downloads and re-uploads a copied image or fileimportAttachmentRecordimportContextRecordsimportContextFragmentcountReservedAttachmentsdownloadAttachmentBlob, which only the import uses
The hook reads the draft-store adders itself instead of taking them from the composer. It returns the import functions, their existing stable forms, the slot counter, and loadThreadTranscript, which thread drops still use. It is called where the import code started, so hook and effect order are unchanged. This PR adds no useStableCallback.
| File | before | after |
|---|---|---|
| ChatComposer.tsx | 4,860 | 4,570 |
| useComposerContextImport.ts | 398 |
Renders are unchanged. This layer moves logic, not render boundaries.
Tested:
- apps/web typecheck and lint on the touched files.
- React Compiler: 0 bailouts on both files.
- Hands-on in a dev build. Pasting an image attaches it and adds its inline chip. Stashing that prompt and restoring it brings back the image and the chip, which goes through
importContextRecords. - Not tested by hand: pasting a context fragment copied from another composer. The headless browser could not round-trip the clipboard.
🤖 Generated with Claude Code
Checks
Added 1 commit
- refactor(web): composer context imports live in useComposerContextImportd7b37b8
Approvability
Verdict: Approved at d7b37b8
Macroscope's review found this PR approvable — This is a focused extraction of existing composer context-import and attachment-counting logic into a dedicated hook, with unchanged call sites and behavior. It introduces no new capability, schema change, product-default change, or static-analysis override.
You can add or adjust custom eligibility rules. Learn more.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
6a7a6116-3716-47cb-af73-1c5cb7161c11
📥 Commits
Reviewing files that changed from the base of the PR and between 25fa572eba1b8a200711bee4bb5b3acc7e39e5c0 and d7b37b81c32eeb84d581993d1906bd32d907feaa.
📒 Files selected for processing: 2
apps/web/src/components/chat/ChatComposer.tsxapps/web/src/components/chat/useComposerContextImport.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
📝 Walkthrough
ChatComposernow delegates context imports touseComposerContextImport. The hook handles attachment retrieval, draft and attachment limits, context-record deduplication and ID reminting, foreign-thread filtering, and transcript loading.Changes: Composer context import
Layer / File(s) Summary Attachment import workflow
apps/web/src/components/chat/useComposerContextImport.ts,apps/web/src/components/chat/ChatComposer.tsxThe hook counts reserved attachments and handles copied-file reuse or source-environment downloads. It checks the draft target and attachment limit, tracks pending work, and reports download failures. Context-record import
apps/web/src/components/chat/useComposerContextImport.tsThe hook orders annotations before screenshots, detects equivalent payloads, remints conflicting IDs, rewrites references, filters foreign threads, and exposes import callbacks and transcript loading. Composer integration
apps/web/src/components/chat/ChatComposer.tsxThe component replaces its inline import logic with the hook and passes draft, attachment, pending-work, context-record, and file-insertion state. It removes related legacy imports and the local download helper. Priority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Refactor
Suggested reviewers:
maria-rcks
Merge Risk: ⚪ Minimal · up to d7b37
This is a refactor that moves composer context-import code into its own hook without intended behavior changes. No concrete regression was identified, so the merge risk is minimal. Context fragments copied between composers are the one path that was not hand-tested.
Pre-merge checks: Passed 3 · Failed 1
Failed Failed checks: 1 warning
Check name Status Explanation Resolution Description check Warning The description clearly explains the refactor and includes focused verification results. It does not follow the required template structure because it omits the Problem and Scope and approval sections… Add the required Problem, Change, Scope and approval, and Verification headings. Describe the prior problem and expected behavior. Link the triaged issue or maintainer approval, or explain why this focused refactor qualifies for an exemptio… Passed Passed checks: 3 passed
Check name Status Explanation Title check Passed The title clearly and concisely identifies the main change: moving composer context-import logic into useComposerContextImport. Linked Issues check Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check
Explanation
The description clearly explains the refactor and includes focused verification results. It does not follow the required template structure because it omits the Problem and Scope and approval sections, and it does not provide the required issue or maintainer-approval information. The verification section is also not explicitly labeled.
Resolution
Add the required Problem, Change, Scope and approval, and Verification headings. Describe the prior problem and expected behavior. Link the triaged issue or maintainer approval, or explain why this focused refactor qualifies for an exemption. Keep the reported test results under Verification and state the untested cross-composer clipboard case.
✨ Finishing Touches
📝 Generate docstrings
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
- Commit to this branch
- Create a new PR
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.