From 4cf99d2e378ab1706382ce73ca1d1ba8e99f4694 Mon Sep 17 00:00:00 2001 From: Ammar Date: Sun, 14 Dec 2025 11:52:29 -0600 Subject: [PATCH] perf: exit splash screen immediately after workspace.create() Switch to the workspace view as soon as workspace.create() succeeds, rather than waiting for sendMessage() to complete. The sendMessage RPC is fired in the background since: 1. Stream errors are handled by the workspace UI via stream-error events 2. sendMessage returns quickly after kicking off the stream 3. The user can see the workspace UI while streaming starts This reduces perceived latency by eliminating the sendMessage RPC round-trip from the splash screen duration. --- .../ChatInput/useCreationWorkspace.ts | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/browser/components/ChatInput/useCreationWorkspace.ts b/src/browser/components/ChatInput/useCreationWorkspace.ts index ed389db5e2..1fb6851465 100644 --- a/src/browser/components/ChatInput/useCreationWorkspace.ts +++ b/src/browser/components/ChatInput/useCreationWorkspace.ts @@ -14,7 +14,6 @@ import { getProjectScopeId, } from "@/common/constants/storage"; import type { Toast } from "@/browser/components/ChatInputToast"; -import { createErrorToast } from "@/browser/components/ChatInputToasts"; import { useAPI } from "@/browser/contexts/API"; import type { ImagePart } from "@/common/orpc/types"; import { @@ -196,8 +195,21 @@ export function useCreationWorkspace({ const { metadata } = createResult; - // Now send the message to the newly created workspace - const result = await api.workspace.sendMessage({ + // Sync preferences immediately (before switching) + syncCreationPreferences(projectPath, metadata.id); + if (projectPath) { + const pendingInputKey = getInputKey(getPendingScopeId(projectPath)); + updatePersistedState(pendingInputKey, ""); + } + + // Switch to the workspace IMMEDIATELY after creation to exit splash faster. + // The user sees the workspace UI while sendMessage kicks off the stream. + onWorkspaceCreated(metadata); + setIsSending(false); + + // Fire sendMessage in the background - stream errors will be shown in the workspace UI + // via the normal stream-error event handling. We don't await this. + void api.workspace.sendMessage({ workspaceId: metadata.id, message: messageText, options: { @@ -206,22 +218,6 @@ export function useCreationWorkspace({ }, }); - if (!result.success) { - setToast(createErrorToast(result.error)); - setIsSending(false); - return false; - } - - // Sync preferences and complete - syncCreationPreferences(projectPath, metadata.id); - if (projectPath) { - const pendingInputKey = getInputKey(getPendingScopeId(projectPath)); - updatePersistedState(pendingInputKey, ""); - } - // Settings are already persisted via useDraftWorkspaceSettings - // Notify parent to switch workspace (clears input via parent unmount) - onWorkspaceCreated(metadata); - setIsSending(false); return true; } catch (err) { const errorMessage = err instanceof Error ? err.message : String(err);