@@ -144,7 +144,7 @@ import {
144144import { ComposerActivityRow } from "./ComposerActivityStatus" ;
145145import {
146146 reconcileAttachmentContextReferences ,
147- type RetainedAttachmentContextPayloads ,
147+ useRetainedContextPayloads ,
148148} from "./composerContextUndo" ;
149149import type { ThreadSyncPhase } from "../../threadSync" ;
150150import { ComposerBanner } from "./ComposerBanner" ;
@@ -3709,20 +3709,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
37093709 setIsComposerScrollCollapsed ( false ) ;
37103710 } , [ setIsComposerScrollCollapsed ] ) ;
37113711
3712- /**
3713- * Payloads for chips the prompt no longer references. History undo restores the
3714- * reference text but knows nothing about the draft records behind it, so a delete keeps its
3715- * payload here and an undo puts it back rather than leaving a dangling chip.
3716- */
3717- const removedContextPayloadsRef = useRef < {
3718- terminals : Map < string , TerminalContextDraft > ;
3719- reviewComments : Map < string , ReviewCommentContext > ;
3720- threads : Map < string , ThreadContextRecord > ;
3721- } > ( { terminals : new Map ( ) , reviewComments : new Map ( ) , threads : new Map ( ) } ) ;
3722- const removedAttachmentContextPayloadsRef = useRef < RetainedAttachmentContextPayloads > ( {
3723- files : new Map ( ) ,
3724- previewAnnotations : new Map ( ) ,
3725- } ) ;
3712+ const retainedContextPayloads = useRetainedContextPayloads ( composerDraftTargetKey ) ;
37263713
37273714 const onPromptChange = useCallback (
37283715 (
@@ -3758,15 +3745,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
37583745 promptHistoryPositionRef . current = null ;
37593746 }
37603747 const referenced = new Set ( contextIds ) ;
3761- const retained = removedContextPayloadsRef . current ;
37623748
37633749 // An undone delete brings the reference back; restore the payload it points at.
37643750 const liveTerminalIds = new Set < string > (
37653751 composerTerminalContexts . map ( ( context ) => terminalContextReference ( context ) . contextId ) ,
37663752 ) ;
37673753 const restoredTerminals = [ ...referenced ] . flatMap ( ( contextId ) => {
37683754 if ( liveTerminalIds . has ( contextId ) ) return [ ] ;
3769- const context = retained . terminals . get ( contextId ) ;
3755+ const context = retainedContextPayloads . terminals . get ( contextId ) ;
37703756 return context ? [ context ] : [ ] ;
37713757 } ) ;
37723758 const nextTerminals = [
@@ -3777,7 +3763,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
37773763 ] ;
37783764 for ( const context of composerTerminalContexts ) {
37793765 const contextId = terminalContextReference ( context ) . contextId ;
3780- if ( ! referenced . has ( contextId ) ) retained . terminals . set ( contextId , context ) ;
3766+ if ( ! referenced . has ( contextId ) ) retainedContextPayloads . terminals . set ( contextId , context ) ;
37813767 }
37823768 if (
37833769 nextTerminals . length !== composerTerminalContexts . length ||
@@ -3791,15 +3777,16 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
37913777 ) ;
37923778 const restoredThreads = [ ...referenced ] . flatMap ( ( contextId ) => {
37933779 if ( liveThreadIds . has ( contextId ) ) return [ ] ;
3794- const record = retained . threads . get ( contextId ) ;
3780+ const record = retainedContextPayloads . threads . get ( contextId ) ;
37953781 return record ? [ record ] : [ ] ;
37963782 } ) ;
37973783 const nextThreads = [
37983784 ...composerThreadContexts . filter ( ( record ) => referenced . has ( record . contextId ) ) ,
37993785 ...restoredThreads ,
38003786 ] ;
38013787 for ( const record of composerThreadContexts ) {
3802- if ( ! referenced . has ( record . contextId ) ) retained . threads . set ( record . contextId , record ) ;
3788+ if ( ! referenced . has ( record . contextId ) )
3789+ retainedContextPayloads . threads . set ( record . contextId , record ) ;
38033790 }
38043791 if ( nextThreads . length !== composerThreadContexts . length || restoredThreads . length > 0 ) {
38053792 setComposerDraftThreadContexts ( composerDraftTarget , nextThreads ) ;
@@ -3808,7 +3795,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
38083795 for ( const comment of composerReviewComments ) {
38093796 const contextId = reviewCommentContextId ( comment . id ) ;
38103797 if ( ! referenced . has ( contextId ) ) {
3811- retained . reviewComments . set ( contextId , comment ) ;
3798+ retainedContextPayloads . reviewComments . set ( contextId , comment ) ;
38123799 removeComposerDraftReviewComment ( composerDraftTarget , comment . id ) ;
38133800 }
38143801 }
@@ -3817,7 +3804,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
38173804 ) ;
38183805 for ( const contextId of referenced ) {
38193806 if ( liveReviewIds . has ( contextId ) ) continue ;
3820- const comment = retained . reviewComments . get ( contextId ) ;
3807+ const comment = retainedContextPayloads . reviewComments . get ( contextId ) ;
38213808 if ( comment ) {
38223809 addComposerDraftReviewComment ( composerDraftTarget , comment , { appendReference : false } ) ;
38233810 }
@@ -3828,7 +3815,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
38283815 files : composerFiles ,
38293816 images : composerImages ,
38303817 previewAnnotations : composerPreviewAnnotations ,
3831- retained : removedAttachmentContextPayloadsRef . current ,
3818+ retained : retainedContextPayloads ,
38323819 } ) ;
38333820 for ( const annotationId of attachmentChanges . annotationIdsToRemove ) {
38343821 // Keep the upload queue entry alive: undo restores the image that owns it.
@@ -3878,6 +3865,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
38783865 addComposerDraftImages ,
38793866 addComposerDraftFiles ,
38803867 attachmentDraftTarget ,
3868+ retainedContextPayloads ,
38813869 ] ,
38823870 ) ;
38833871
0 commit comments