Skip to content

Commit 25008cb

Browse files
committed
Optimistically update workspace cache to prevent setup screen flash
1 parent 62ef246 commit 25008cb

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

  • apps/code/src/renderer/features/task-detail/service

apps/code/src/renderer/features/task-detail/service/service.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useAuthStore } from "@features/auth/stores/authStore";
22
import { useDraftStore } from "@features/message-editor/stores/draftStore";
33
import { useSettingsStore } from "@features/settings/stores/settingsStore";
44
import { workspaceApi } from "@features/workspace/hooks/useWorkspace";
5+
import type { Workspace } from "@main/services/workspace/schemas";
56
import type { SagaResult } from "@posthog/shared";
67
import {
78
type TaskCreationInput,
@@ -60,6 +61,7 @@ export class TaskService {
6061
const result = await saga.run(input);
6162

6263
if (result.success) {
64+
this.optimisticallyUpdateWorkspaceCache(result.data);
6365
this.updateStoresOnSuccess(result.data, input);
6466
void queryClient.invalidateQueries({
6567
queryKey: [["workspace", "getAll"]],
@@ -124,6 +126,7 @@ export class TaskService {
124126
const result = await saga.run({ taskId });
125127

126128
if (result.success) {
129+
this.optimisticallyUpdateWorkspaceCache(result.data);
127130
this.updateStoresOnSuccess(result.data);
128131
void queryClient.invalidateQueries({
129132
queryKey: [["workspace", "getAll"]],
@@ -151,6 +154,17 @@ export class TaskService {
151154
return result;
152155
}
153156

157+
private optimisticallyUpdateWorkspaceCache(
158+
output: TaskCreationOutput,
159+
): void {
160+
if (!output.workspace) return;
161+
const workspace = output.workspace;
162+
queryClient.setQueriesData<Record<string, Workspace>>(
163+
{ queryKey: [["workspace", "getAll"]] },
164+
(old) => ({ ...old, [output.task.id]: workspace }),
165+
);
166+
}
167+
154168
/**
155169
* Batch update stores after successful task creation/open.
156170
*/

0 commit comments

Comments
 (0)