@@ -89,8 +89,12 @@ export function useComposer({
8989 const attachDisabled = submitting || attachments . length >= MAX_ATTACHMENTS ;
9090
9191 const handleClose = useCallback ( ( ) => {
92- if ( ! submitting ) onClose ( ) ;
93- } , [ submitting , onClose ] ) ;
92+ if ( submitting ) return ;
93+ onClose ( ) ;
94+ // Reset here too: the native compose tab stays mounted after closing,
95+ // so the unmount reset below wouldn't fire for it.
96+ resetComposer ( ) ;
97+ } , [ submitting , onClose , resetComposer ] ) ;
9498
9599 const handleAttachImage = useCallback ( async ( ) => {
96100 if ( attachDisabled ) return ;
@@ -109,13 +113,34 @@ export function useComposer({
109113 height : asset . height ,
110114 } ) ) ;
111115 addAttachments ( additions ) ;
112- } , [ attachDisabled , attachments . length , addAttachments ] ) ;
116+ setError ( null ) ;
117+ } , [ attachDisabled , attachments . length , addAttachments , setError ] ) ;
113118
114119 const handleRemoveAttachment = useCallback (
115- ( id : string ) => removeAttachment ( id ) ,
116- [ removeAttachment ] ,
120+ ( id : string ) => {
121+ removeAttachment ( id ) ;
122+ setError ( null ) ;
123+ } ,
124+ [ removeAttachment , setError ] ,
125+ ) ;
126+
127+ // Editing the draft (text or images) clears any prior post error.
128+ const handleTextChange = useCallback (
129+ ( next : string ) => {
130+ setText ( next ) ;
131+ setError ( null ) ;
132+ } ,
133+ [ setText , setError ] ,
117134 ) ;
118135
136+ // Reset the entire composer (text, attachments, submitting, error) when
137+ // it closes (unmounts), so nothing carries over to the next open.
138+ useEffect ( ( ) => {
139+ return ( ) => {
140+ resetComposer ( ) ;
141+ } ;
142+ } , [ resetComposer ] ) ;
143+
119144 // Auto-open the image picker once when the caller requested it
120145 // (e.g. tapping the attach icon in the inline composer).
121146 const attachOnMountFiredRef = useRef ( false ) ;
@@ -236,7 +261,7 @@ export function useComposer({
236261 return {
237262 // state
238263 text,
239- setText,
264+ setText : handleTextChange ,
240265 attachments,
241266 submitting,
242267 error,
0 commit comments