@@ -276,17 +276,21 @@ export const CodeViewWrapper = memo(
276276 } )
277277 }
278278
279- // Per-keystroke updates from a draft's CommentForm. Cheap Map copy — draft
280- // counts are always small (one open form per line range a reviewer is
281- // actively commenting on).
282- const updateDraft = ( key : string , patch : Partial < Pick < DraftMetadata , 'body' | 'suggestMode' | 'suggestionText' > > ) => {
283- setPending ( ( prev ) => {
284- const existing = prev . get ( key )
285- if ( ! existing ) return prev
286- const next = new Map ( prev )
287- next . set ( key , { ...existing , ...patch } )
288- return next
289- } )
279+ // Per-keystroke updates from a draft's CommentForm. Deliberately mutates
280+ // the draft object in place instead of going through setPending: these
281+ // fields don't affect where the annotation renders, and a state update
282+ // here would ripple through the annotations effect into
283+ // viewer.updateItem() — which rebuilds the file's entire annotation DOM
284+ // on every keystroke, remounting every open form and bubble, stealing
285+ // focus to another form's mount-autofocus and snapping scroll to it.
286+ // The draft object is the same reference held by both the `pending` map
287+ // and the annotation metadata, so a real remount (structural refetch)
288+ // still seeds CommentForm with the freshest text via the initial* props.
289+ const updateDraft = (
290+ draft : DraftMetadata ,
291+ patch : Partial < Pick < DraftMetadata , 'body' | 'suggestMode' | 'suggestionText' > > ,
292+ ) => {
293+ Object . assign ( draft , patch )
290294 }
291295
292296 useImperativeHandle (
@@ -693,9 +697,9 @@ export const CodeViewWrapper = memo(
693697 initialBody = { p . body }
694698 initialSuggestMode = { p . suggestMode }
695699 initialSuggestionText = { p . suggestionText }
696- onBodyChange = { ( body ) => updateDraft ( draftKey ( p ) , { body } ) }
697- onSuggestModeChange = { ( suggestMode ) => updateDraft ( draftKey ( p ) , { suggestMode } ) }
698- onSuggestionTextChange = { ( suggestionText ) => updateDraft ( draftKey ( p ) , { suggestionText } ) }
700+ onBodyChange = { ( body ) => updateDraft ( p , { body } ) }
701+ onSuggestModeChange = { ( suggestMode ) => updateDraft ( p , { suggestMode } ) }
702+ onSuggestionTextChange = { ( suggestionText ) => updateDraft ( p , { suggestionText } ) }
699703 onSubmit = { ( body , suggestion ) => {
700704 const lineContent = getRangeContent (
701705 item . fileDiff ,
0 commit comments