@@ -126,6 +126,7 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
126126 console . error ( "AppStateContext is undefined. Ensure AppProvider wraps this component." ) ;
127127 return null ; // Prevents execution if context is missing
128128 }
129+ const [ loadingState , setLoadingState ] = useState ( appStateContext . state . isLoading ) ;
129130 const { currentChat } = appStateContext ?. state ;
130131
131132 const errorDialogContentProps = {
@@ -158,6 +159,10 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
158159 appStateContext ?. dispatch ( { type : 'GENERATE_ISLODING' , payload : appStateContext ?. state . isGenerating } )
159160 } , [ isLoading ] )
160161
162+ useEffect ( ( ) => {
163+ setLoadingState ( appStateContext . state . isLoading )
164+ } , [ appStateContext . state . isLoading ] )
165+
161166 useEffect ( ( ) => {
162167 if (
163168 appStateContext ?. state . isCosmosDBAvailable ?. status !== CosmosDBStatus . Working &&
@@ -837,23 +842,24 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
837842 ) : (
838843 < Stack horizontal className = { styles . chatRoot } >
839844 < div className = { styles . chatContainer } >
840- { appStateContext . state . isLoading ? (
841- < Stack horizontalAlign = "center" verticalAlign = "center" className = { styles . chatLoadingState } style = { { padding : 250 , paddingBottom : 150 } } >
842- < Spinner label = "Loading your chat..." size = { SpinnerSize . large } />
843- </ Stack >
844- ) : currentChat ?. messages && currentChat . messages . length > 0 ? (
845+ { loadingState ? (
846+ < Stack horizontalAlign = "center" verticalAlign = "center" className = { styles . chatLoadingState } style = { { padding : 250 , paddingBottom : 150 } } >
847+ < Spinner label = "Loading your chat..." size = { SpinnerSize . large } />
848+ </ Stack >
849+ ) : ! messages || messages . length < 1 ? (
850+ < Stack className = { styles . chatEmptyState } >
851+ < h1 className = { styles . chatEmptyStateTitle } > { ui ?. chat_title } </ h1 >
852+ </ Stack >
853+ ) : (
854+ // Show chat messages while loading continues in the background
845855 < ChatMessageContainer
846- messages = { currentChat . messages }
847- isLoading = { isLoading }
856+ messages = { messages }
857+ isLoading = { isLoading } // Keep isLoading for progressive updates
848858 type = { type }
849859 onShowCitation = { onShowCitation }
850860 showLoadingMessage = { showLoadingMessage }
851861 ref = { chatMessageStreamEnd }
852862 />
853- ) : (
854- < Stack className = { styles . chatEmptyState } >
855- < h1 className = { styles . chatEmptyStateTitle } > { ui ?. chat_title } </ h1 >
856- </ Stack >
857863 ) }
858864
859865 < Stack horizontal className = { styles . chatInput } >
0 commit comments