@@ -166,10 +166,11 @@ const ContentPanel: FunctionComponent<IContentPanelProps> = ({ props }) => {
166166
167167 const elements : ContentPanelElements = React . useMemo ( ( ) => new ContentPanelElements ( props ) , [ ] ) ;
168168 const refLatestResponseFromAi = React . useRef < HTMLDivElement > ( null ) ;
169+ const refLatestResponseFromAiInCustomPanel = React . useRef < HTMLDivElement > ( null ) ;
169170
170171 return (
171172 < >
172- { getContentPanel ( refPanelContentPane , refPrompt , refConversationContainer ) }
173+ { getContentPanel ( refPanelContentPane , refPrompt , refConversationContainer , refLatestResponseFromAi ) }
173174 { isCustomPanelOpen !== undefined && (
174175 < Panel
175176 className = { styles . customPanel }
@@ -185,7 +186,12 @@ const ContentPanel: FunctionComponent<IContentPanelProps> = ({ props }) => {
185186 type = { PanelType . custom }
186187 >
187188 < span className = { styles . container } >
188- { getContentPanel ( refPanelContentPaneInCustomPanel , refPromptInCustomPanel , refConversationContainerInCustomPanel ) }
189+ { getContentPanel (
190+ refPanelContentPaneInCustomPanel ,
191+ refPromptInCustomPanel ,
192+ refConversationContainerInCustomPanel ,
193+ refLatestResponseFromAiInCustomPanel
194+ ) }
189195 < TooltipHost content = { strings . TextClose } >
190196 < FontIcon className = { styles . closepanel } iconName = { 'ChromeClose' } onClick = { ( ) => setIsCustomPanelOpen ( false ) } />
191197 </ TooltipHost >
@@ -275,12 +281,16 @@ const ContentPanel: FunctionComponent<IContentPanelProps> = ({ props }) => {
275281 function getContentPanel (
276282 refContentPane : React . LegacyRef < HTMLDivElement > ,
277283 refPromptArea : React . LegacyRef < HTMLTextAreaElement > ,
278- refNavigation : React . LegacyRef < HTMLDivElement >
284+ refNavigation : React . LegacyRef < HTMLDivElement > ,
285+ refLatestResponse : React . LegacyRef < HTMLDivElement >
279286 ) : JSX . Element {
280287 if ( ! Array . isArray ( chatHistory ) ) LogService . error ( 'Invalid data format: chatHistory is not an array' ) ;
281288 const rows =
282289 Array . isArray ( chatHistory ) && chatHistory ?. length > 0
283- ? getChatHistoryContent ( chatHistory . filter ( ( r ) => typeof r . content === 'string' ) )
290+ ? getChatHistoryContent (
291+ chatHistory . filter ( ( r ) => typeof r . content === 'string' ) ,
292+ refLatestResponse
293+ )
284294 : [ ] ;
285295
286296 const fileUpload = elements . getFileUpload (
@@ -520,6 +530,8 @@ const ContentPanel: FunctionComponent<IContentPanelProps> = ({ props }) => {
520530 } ;
521531
522532 const handleResponseStream = ( response , firstResponse : boolean ) => {
533+ const isRefLatestResponse =
534+ refLatestResponseFromAi . current !== null || refLatestResponseFromAiInCustomPanel . current !== null ;
523535 if ( response ) {
524536 // The next line is important. It enforces the correct state change by changing array's memory address to new one.
525537 newChatHistory = [ ...newChatHistory ] ;
@@ -538,8 +550,9 @@ const ContentPanel: FunctionComponent<IContentPanelProps> = ({ props }) => {
538550 assistantResponses [ assistantResponses . length - 1 ] . content += ChatHelper . cleanupResponseContent ( response ) ;
539551 const queryParameters = new URLSearchParams ( window . location . search ) ;
540552 const prev = queryParameters . get ( 'prev' ) ;
541- if ( ! prev && refLatestResponseFromAi . current ) {
542- refLatestResponseFromAi . current . innerHTML += response ;
553+ if ( ! prev && isRefLatestResponse ) {
554+ if ( refLatestResponseFromAi . current ) refLatestResponseFromAi . current . innerHTML += response ;
555+ if ( refLatestResponseFromAiInCustomPanel . current ) refLatestResponseFromAiInCustomPanel . current . innerHTML += response ;
543556 } else {
544557 const messageSelector = isCustomPanelOpen
545558 ? `.${ styles . customPanel } .${ styles . message } `
@@ -678,7 +691,7 @@ const ContentPanel: FunctionComponent<IContentPanelProps> = ({ props }) => {
678691 }
679692 }
680693
681- function getChatHistoryContent ( rows : IChatHistory [ ] ) : JSX . Element [ ] {
694+ function getChatHistoryContent ( rows : IChatHistory [ ] , refLatestResponse : React . LegacyRef < HTMLDivElement > ) : JSX . Element [ ] {
682695 // Performance improvement to eliminate delays related to rendering of large chats with many code bocks.
683696 const formattedRows = props . highlight
684697 ? rows . map ( ( r , index ) => {
@@ -717,7 +730,7 @@ const ContentPanel: FunctionComponent<IContentPanelProps> = ({ props }) => {
717730 < div
718731 id = { chatMessageId }
719732 className = { [ 'ai' , styles . message , isCustomPanelOpen ? styles . insidePanel : undefined ] . join ( ' ' ) . trim ( ) }
720- ref = { refLatestResponseFromAi }
733+ ref = { refLatestResponse }
721734 >
722735 { ! disabledHighlights ?. find ( ( id ) => id === chatMessageId ) ? formattedRows [ index ] : content }
723736 </ div >
@@ -726,7 +739,7 @@ const ContentPanel: FunctionComponent<IContentPanelProps> = ({ props }) => {
726739 id = { chatMessageId }
727740 className = { [ 'ai' , styles . message ] . join ( ' ' ) }
728741 dangerouslySetInnerHTML = { { __html : r . content } }
729- ref = { refLatestResponseFromAi }
742+ ref = { refLatestResponse }
730743 />
731744 )
732745 ) : (
0 commit comments