File tree Expand file tree Collapse file tree
apps/web/src/components/chat Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import type { PreviewAnnotationPayload , ThreadContextRecord } from "@t3tools/contracts" ;
2- import { useState } from "react" ;
2+ import { useEffect , useState } from "react" ;
33
44import type { ComposerFileAttachment , ComposerImageAttachment } from "../../composerDraftStore" ;
55import { fileContextReference , previewAnnotationContextId } from "../../lib/composerContextRecords" ;
@@ -32,8 +32,7 @@ function createRetainedContextPayloads(): RetainedContextPayloads {
3232 } ;
3333}
3434
35- // Deleted chips keep their payloads until their draft's undo history ends. Switching drafts
36- // swaps in fresh maps; the dropped ones are unreachable and collected with that history.
35+ // Deleted chips keep their payloads until their draft's undo history ends.
3736export function useRetainedContextPayloads ( draftTargetKey : string ) : RetainedContextPayloads {
3837 const [ draft , setDraft ] = useState ( ( ) => ( {
3938 targetKey : draftTargetKey ,
@@ -42,7 +41,14 @@ export function useRetainedContextPayloads(draftTargetKey: string): RetainedCont
4241 if ( draft . targetKey !== draftTargetKey ) {
4342 setDraft ( { targetKey : draftTargetKey , payloads : createRetainedContextPayloads ( ) } ) ;
4443 }
45- return draft . payloads ;
44+ const retained = draft . payloads ;
45+ useEffect (
46+ ( ) => ( ) => {
47+ for ( const payloads of Object . values ( retained ) ) payloads . clear ( ) ;
48+ } ,
49+ [ retained ] ,
50+ ) ;
51+ return retained ;
4652}
4753
4854export function reconcileAttachmentContextReferences ( input : {
You can’t perform that action at this time.
0 commit comments