Skip to content

The agent that grows with you

fix(desktop): a signed-out Webapp tab keeps no conversation on the page

emozilla0d691d1deaca
diff --git a/apps/desktop/src/components/assistant-ui/thread/index.test.tsx b/apps/desktop/src/components/assistant-ui/thread/index.test.tsx
index 6e06c4ee304..793713644f6 100644
--- a/apps/desktop/src/components/assistant-ui/thread/index.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/index.test.tsx
@@ -32,6 +32,8 @@ vi.mock('@/components/assistant-ui/thread/status', () => ({
}))
vi.mock('@/i18n', () => ({
+ // Boot state, which the transcript reads to know whether the tab is signed out, labels itself.
+ translateNow: (key: string) => key,
useI18n: () => ({
t: {
assistant: {
diff --git a/apps/desktop/src/components/assistant-ui/thread/index.tsx b/apps/desktop/src/components/assistant-ui/thread/index.tsx
index 8859efa6856..af5d0fff07e 100644
--- a/apps/desktop/src/components/assistant-ui/thread/index.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/index.tsx
@@ -1,3 +1,4 @@
+import { useStore } from '@nanostores/react'
import { createContext, memo, useCallback, useContext, useMemo, useRef, useState } from 'react'
import { ChatEmptySlot } from '@/components/assistant-ui/chat-empty-slot'
@@ -14,6 +15,7 @@ import { Intro, type IntroProps } from '@/components/chat/intro'
import { ConfirmDialog } from '@/components/ui/confirm-dialog'
import type { HermesGateway } from '@/hermes'
import { useI18n } from '@/i18n'
+import { $webappSignedOut } from '@/store/boot'
import { notifyError } from '@/store/notifications'
type ThreadLoadingState = 'response' | 'session'
@@ -73,6 +75,9 @@ export const Thread = memo(function Thread({
const { t } = useI18n()
const copy = t.assistant.thread
const { isHistorical } = useTranscriptWindow()
+ // A signed-out Webapp tab keeps no conversation on the page under its sign-in view; the
+ // messages mount again from the session once the tab signs back in.
+ const signedOut = useStore($webappSignedOut)
if (isHistorical) {
onBranchInNewChat = undefined
@@ -184,18 +189,22 @@ export const Thread = memo(function Thread({
className="relative grid h-full min-h-0 max-w-full grid-rows-[minmax(0,1fr)] overflow-hidden bg-transparent contain-[layout_paint]"
data-slot="thread"
>
- <ThreadMessageList
- clampToComposer={clampToComposer}
- components={messageComponents}
- emptyPlaceholder={emptyPlaceholder}
- loadingIndicator={loadingIndicator}
- scrollProfile={scrollProfile}
- sessionId={sessionId}
- sessionKey={sessionKey}
- sessionLoading={loading === 'session'}
- />
- {loading === 'session' && <CenteredThreadSpinner />}
- <ThreadTimeline />
+ {!signedOut && (
+ <>
+ <ThreadMessageList
+ clampToComposer={clampToComposer}
+ components={messageComponents}
+ emptyPlaceholder={emptyPlaceholder}
+ loadingIndicator={loadingIndicator}
+ scrollProfile={scrollProfile}
+ sessionId={sessionId}
+ sessionKey={sessionKey}
+ sessionLoading={loading === 'session'}
+ />
+ {loading === 'session' && <CenteredThreadSpinner />}
+ <ThreadTimeline />
+ </>
+ )}
<ConfirmDialog
confirmLabel={copy.restoreConfirm}
description={copy.restoreBody}
diff --git a/apps/desktop/src/components/assistant-ui/thread/signed-out-transcript.test.tsx b/apps/desktop/src/components/assistant-ui/thread/signed-out-transcript.test.tsx
new file mode 100644
index 00000000000..11efaf61643
--- /dev/null
+++ b/apps/desktop/src/components/assistant-ui/thread/signed-out-transcript.test.tsx
@@ -0,0 +1,62 @@
+import { AssistantRuntimeProvider, type ThreadMessage, useExternalStoreRuntime } from '@assistant-ui/react'
+import { act, cleanup, render, screen } from '@testing-library/react'
+import { afterEach, describe, expect, it } from 'vitest'
+
+import { WEBAPP_LAUNCH_REQUIRED } from '@/lib/browser-launch-session'
+import { completeDesktopBoot, failDesktopBoot } from '@/store/boot'
+
+import { assistantMessage, stubThreadEnvironment, stubThreadViewportSize, userMessage } from '../test-utils'
+
+import { Thread } from '.'
+
+stubThreadEnvironment()
+stubThreadViewportSize()
+
+function Harness() {
+ const runtime = useExternalStoreRuntime<ThreadMessage>({
+ messages: [userMessage(), assistantMessage()],
+ isRunning: false,
+ onNew: async () => {}
+ })
+
+ return (
+ <AssistantRuntimeProvider runtime={runtime}>
+ <Thread />
+ </AssistantRuntimeProvider>
+ )
+}
+
+afterEach(() => {
+ cleanup()
+ completeDesktopBoot()
+})
+
+describe('transcript while a Webapp tab is signed out', () => {
+ // After sign-out the sign-in view covers the tab. The conversation must not stay on the page
+ // underneath it, where removing the overlay would show it; it comes back once the tab is signed
+ // in again.
+ it('leaves the page while the sign-in view is up and returns after sign-in', async () => {
+ render(<Harness />)
+ expect(await screen.findByText('edit me please')).toBeTruthy()
+ expect(screen.getByText('done')).toBeTruthy()
+
+ act(() => failDesktopBoot(WEBAPP_LAUNCH_REQUIRED))
+
+ expect(screen.queryByText('edit me please')).toBeNull()
+ expect(screen.queryByText('done')).toBeNull()
+
+ act(() => completeDesktopBoot())
+
+ expect(await screen.findByText('edit me please')).toBeTruthy()
+ expect(screen.getByText('done')).toBeTruthy()
+ })
+
+ it('keeps the transcript under any other startup failure', async () => {
+ render(<Harness />)
+ expect(await screen.findByText('edit me please')).toBeTruthy()
+
+ act(() => failDesktopBoot('Gateway exited during startup'))
+
+ expect(screen.getByText('edit me please')).toBeTruthy()
+ })
+})
diff --git a/apps/desktop/src/store/boot.ts b/apps/desktop/src/store/boot.ts
index 0600c27d330..bea84c89e50 100644
--- a/apps/desktop/src/store/boot.ts
+++ b/apps/desktop/src/store/boot.ts
@@ -1,7 +1,8 @@
-import { atom } from 'nanostores'
+import { atom, computed } from 'nanostores'
import type { DesktopBootProgress, UpdateHoldWire } from '@/global'
import { translateNow } from '@/i18n'
+import { WEBAPP_LAUNCH_REQUIRED } from '@/lib/browser-launch-session'
export interface DesktopBootState extends DesktopBootProgress {
visible: boolean
@@ -20,6 +21,9 @@ const INITIAL_BOOT_STATE: DesktopBootState = {
export const $desktopBoot = atom<DesktopBootState>(INITIAL_BOOT_STATE)
+/** A Webapp tab whose sign-in ended: the sign-in view covers it until it signs in again. */
+export const $webappSignedOut = computed($desktopBoot, boot => Boolean(boot.error?.includes(WEBAPP_LAUNCH_REQUIRED)))
+
function clampProgress(value: number) {
if (!Number.isFinite(value)) {
return 0