Skip to content

Commit 200025b

Browse files
authored
🤖 perf: exit splash screen immediately after workspace.create() (#1146)
Switch to the workspace view as soon as `workspace.create()` succeeds, rather than waiting for `sendMessage()` to complete. ## What changed **Before:** ``` setIsSending(true) await waitForGeneration() await workspace.create(...) await workspace.sendMessage(...) ← blocked here onWorkspaceCreated(metadata) setIsSending(false) ← splash exits ``` **After:** ``` setIsSending(true) await waitForGeneration() await workspace.create(...) onWorkspaceCreated(metadata) ← switch immediately setIsSending(false) ← splash exits void workspace.sendMessage(...) ← fire-and-forget ``` ## Why this is safe 1. **Stream errors handled by workspace UI**: Once switched to the workspace view, the chat UI listens to `stream-error` events and displays them inline 2. **`sendMessage` returns quickly**: The RPC just kicks off the stream in the background via `processStreamWithCleanup()` and returns 3. **No race conditions**: Preferences are synced before switching, and the workspace store is updated atomically This reduces perceived latency by eliminating the `sendMessage` RPC round-trip from the splash screen duration. --- _Generated with `mux` • Model: `anthropic:claude-opus-4-5` • Thinking: `high`_
1 parent 5e4cab3 commit 200025b

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

src/browser/components/ChatInput/useCreationWorkspace.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
getProjectScopeId,
1515
} from "@/common/constants/storage";
1616
import type { Toast } from "@/browser/components/ChatInputToast";
17-
import { createErrorToast } from "@/browser/components/ChatInputToasts";
1817
import { useAPI } from "@/browser/contexts/API";
1918
import type { ImagePart } from "@/common/orpc/types";
2019
import {
@@ -196,8 +195,21 @@ export function useCreationWorkspace({
196195

197196
const { metadata } = createResult;
198197

199-
// Now send the message to the newly created workspace
200-
const result = await api.workspace.sendMessage({
198+
// Sync preferences immediately (before switching)
199+
syncCreationPreferences(projectPath, metadata.id);
200+
if (projectPath) {
201+
const pendingInputKey = getInputKey(getPendingScopeId(projectPath));
202+
updatePersistedState(pendingInputKey, "");
203+
}
204+
205+
// Switch to the workspace IMMEDIATELY after creation to exit splash faster.
206+
// The user sees the workspace UI while sendMessage kicks off the stream.
207+
onWorkspaceCreated(metadata);
208+
setIsSending(false);
209+
210+
// Fire sendMessage in the background - stream errors will be shown in the workspace UI
211+
// via the normal stream-error event handling. We don't await this.
212+
void api.workspace.sendMessage({
201213
workspaceId: metadata.id,
202214
message: messageText,
203215
options: {
@@ -206,22 +218,6 @@ export function useCreationWorkspace({
206218
},
207219
});
208220

209-
if (!result.success) {
210-
setToast(createErrorToast(result.error));
211-
setIsSending(false);
212-
return false;
213-
}
214-
215-
// Sync preferences and complete
216-
syncCreationPreferences(projectPath, metadata.id);
217-
if (projectPath) {
218-
const pendingInputKey = getInputKey(getPendingScopeId(projectPath));
219-
updatePersistedState(pendingInputKey, "");
220-
}
221-
// Settings are already persisted via useDraftWorkspaceSettings
222-
// Notify parent to switch workspace (clears input via parent unmount)
223-
onWorkspaceCreated(metadata);
224-
setIsSending(false);
225221
return true;
226222
} catch (err) {
227223
const errorMessage = err instanceof Error ? err.message : String(err);

0 commit comments

Comments
 (0)