@@ -238,6 +238,7 @@ import {
238238import { ThreadErrorBanner } from "./chat/ThreadErrorBanner" ;
239239import { resolveThreadPr } from "./ThreadStatusIndicators" ;
240240import { ComposerBannerStack , type ComposerBannerStackItem } from "./chat/ComposerBannerStack" ;
241+ import { ThreadSyncStatusPill } from "./chat/ThreadSyncStatusPill" ;
241242import {
242243 DRAFT_HERO_TRANSITION_ANIMATION_ID ,
243244 DRAFT_HERO_TRANSITION_DURATION_MS ,
@@ -251,6 +252,7 @@ import {
251252 branchMismatchKey ,
252253 buildExpiredTerminalContextToastCopy ,
253254 buildLocalDraftThread ,
255+ buildLoadingThreadFromShell ,
254256 buildThreadTurnInterruptInput ,
255257 collectUserMessageBlobPreviewUrls ,
256258 createLocalDispatchSnapshot ,
@@ -275,6 +277,7 @@ import {
275277 startNewThreadForProject ,
276278 waitForStartedServerThread ,
277279} from "./ChatView.logic" ;
280+ import type { ThreadSyncPhase } from "../threadSync" ;
278281import { useLocalStorage } from "~/hooks/useLocalStorage" ;
279282import { useComposerHandleContext } from "../composerHandleContext" ;
280283import { sanitizeThreadErrorMessage } from "~/rpc/transportError" ;
@@ -465,6 +468,7 @@ type ChatViewProps =
465468 onDiffPanelOpen ?: ( ) => void ;
466469 reserveTitleBarControlInset ?: boolean ;
467470 forceExpandedMobileComposer ?: boolean ;
471+ threadSyncPhase ?: ThreadSyncPhase | null ;
468472 routeKind : "server" ;
469473 draftId ?: never ;
470474 }
@@ -474,6 +478,7 @@ type ChatViewProps =
474478 onDiffPanelOpen ?: ( ) => void ;
475479 reserveTitleBarControlInset ?: boolean ;
476480 forceExpandedMobileComposer ?: boolean ;
481+ threadSyncPhase ?: never ;
477482 routeKind : "draft" ;
478483 draftId : DraftId ;
479484 } ;
@@ -1132,6 +1137,8 @@ function ChatViewContent(props: ChatViewProps) {
11321137 forceExpandedMobileComposer = false ,
11331138 } = props ;
11341139 const draftId = routeKind === "draft" ? props . draftId : null ;
1140+ const threadSyncPhase = routeKind === "server" ? ( props . threadSyncPhase ?? null ) : null ;
1141+ const threadDetailLoading = threadSyncPhase === "loading" ;
11351142 const handleNewThread = useNewThreadHandler ( ) ;
11361143 const routeThreadRef = useMemo (
11371144 ( ) => scopeThreadRef ( environmentId , threadId ) ,
@@ -1188,7 +1195,15 @@ function ChatViewContent(props: ChatViewProps) {
11881195 ? store . getDraftSession ( draftId )
11891196 : null ,
11901197 ) ;
1198+ const routeServerThreadShell = useThreadShell ( routeKind === "server" ? routeThreadRef : null ) ;
11911199 const serverThread = useThread ( routeThreadRef , { waitForShell : draftThread !== null } ) ;
1200+ const loadingServerThread = useMemo (
1201+ ( ) =>
1202+ threadDetailLoading && routeServerThreadShell
1203+ ? buildLoadingThreadFromShell ( routeServerThreadShell )
1204+ : null ,
1205+ [ routeServerThreadShell , threadDetailLoading ] ,
1206+ ) ;
11921207 const markThreadVisited = useUiStateStore ( ( store ) => store . markThreadVisited ) ;
11931208 const activeThreadLastVisitedAt = useUiStateStore (
11941209 ( store ) => store . threadLastVisitedAtById [ routeThreadKey ] ,
@@ -1421,10 +1436,11 @@ function ChatViewContent(props: ChatViewProps) {
14211436 // Promotion is data-driven: the draft route keeps rendering while the
14221437 // server thread (same pre-allocated ref) starts, so live state must not
14231438 // depend on which route is mounted.
1424- const isServerThread = serverThread !== null ;
1425- const activeThread = isServerThread ? serverThread : localDraftThread ;
1439+ const activeServerThread = serverThread ?? loadingServerThread ;
1440+ const isServerThread = activeServerThread !== null ;
1441+ const activeThread = activeServerThread ?? localDraftThread ;
14261442 const threadError = isServerThread
1427- ? ( localServerError ?? serverThread ?. session ?. lastError ?? null )
1443+ ? ( localServerError ?? activeServerThread ?. session ?. lastError ?? null )
14281444 : localDraftError ;
14291445 const runtimeMode = composerRuntimeMode ?? activeThread ?. runtimeMode ?? DEFAULT_RUNTIME_MODE ;
14301446 const interactionMode =
@@ -4471,6 +4487,7 @@ function ChatViewContent(props: ChatViewProps) {
44714487 ! activeThread ||
44724488 isSendBusy ||
44734489 isConnecting ||
4490+ threadDetailLoading ||
44744491 activeEnvironmentUnavailable ||
44754492 sendInFlightRef . current
44764493 )
@@ -5737,7 +5754,7 @@ function ChatViewContent(props: ChatViewProps) {
57375754 contentInsetEndAdjustment = { composerOverlayHeight }
57385755 onIsAtEndChange = { onIsAtEndChange }
57395756 onManualNavigation = { cancelTimelineLiveFollowForUserNavigation }
5740- hideEmptyPlaceholder = { isDraftHeroState }
5757+ hideEmptyPlaceholder = { isDraftHeroState || threadDetailLoading }
57415758 topFadeEnabled = { ! hasTimelineTopBanner }
57425759 />
57435760
@@ -5798,6 +5815,9 @@ function ChatViewContent(props: ChatViewProps) {
57985815 ) : (
57995816 < ComposerBannerStack className = "relative z-0" items = { composerBannerItems } />
58005817 ) }
5818+ { threadSyncPhase && ! activeEnvironmentUnavailable ? (
5819+ < ThreadSyncStatusPill phase = { threadSyncPhase } />
5820+ ) : null }
58015821 < div
58025822 className = "relative"
58035823 style = {
@@ -5831,6 +5851,7 @@ function ChatViewContent(props: ChatViewProps) {
58315851 phase = { phase }
58325852 isConnecting = { isConnecting }
58335853 isSendBusy = { isSendBusy }
5854+ sendDisabledReason = { threadDetailLoading ? "Messages loading" : null }
58345855 isPreparingWorktree = { isPreparingWorktree }
58355856 environmentUnavailable = { activeEnvironmentUnavailableState }
58365857 activePendingApproval = { activePendingApproval }
0 commit comments