Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/ui/src/features/settings/settingsStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,33 @@ describe("feature settingsStore cloud selections", () => {

expect(useSettingsStore.getState().allowBypassPermissions).toBe(true);
});

it.each([
["lastUsedWorkspaceMode", "local", "cloud"],
["debugLogsCloudRuns", false, true],
] as const)("rehydrates %s", async (field, initial, persisted) => {
getItem.mockResolvedValue(
JSON.stringify({ state: { [field]: persisted }, version: 0 }),
);

useSettingsStore.setState({ [field]: initial } as Parameters<
typeof useSettingsStore.setState
>[0]);

await useSettingsStore.persist.rehydrate();

expect(useSettingsStore.getState()[field]).toBe(persisted);
});

it("flips _hasHydrated once the persisted snapshot lands", async () => {
getItem.mockResolvedValue(JSON.stringify({ state: {}, version: 0 }));

useSettingsStore.setState({ _hasHydrated: false });

await useSettingsStore.persist.rehydrate();

expect(useSettingsStore.getState()._hasHydrated).toBe(true);
});
});

describe("feature settingsStore terminal font", () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/ui/src/features/settings/settingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ interface SettingsStore {
shouldShowHint: (key: string, max?: number) => boolean;
recordHintShown: (key: string) => void;
markHintLearned: (key: string) => void;

_hasHydrated: boolean;
setHasHydrated: (hydrated: boolean) => void;
}

// ---------- Store ----------
Expand Down Expand Up @@ -259,6 +262,9 @@ export const useSettingsStore = create<SettingsStore>()(
},
};
}),

_hasHydrated: false,
setHasHydrated: (hydrated) => set({ _hasHydrated: hydrated }),
}),
{
name: "settings-storage",
Expand Down Expand Up @@ -309,6 +315,9 @@ export const useSettingsStore = create<SettingsStore>()(
// Onboarding hints
hints: state.hints,
}),
onRehydrateStorage: () => (state) => {
state?.setHasHydrated(true);
},
merge: (persisted, current) => {
const merged = {
...current,
Expand Down
11 changes: 11 additions & 0 deletions packages/ui/src/features/task-detail/components/TaskInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export function TaskInput({
lastUsedInitialTaskMode,
setLastUsedReasoningEffort,
setLastUsedModel,
_hasHydrated: settingsHydrated,
} = useSettingsStore();

const editorRef = useRef<EditorHandle>(null);
Expand Down Expand Up @@ -211,7 +212,17 @@ export function TaskInput({
return lastUsedWorkspaceMode || "local";
});

const didResolveWorkspaceModeRef = useRef(false);
useEffect(() => {
if (didResolveWorkspaceModeRef.current) return;
if (!settingsHydrated) return;
didResolveWorkspaceModeRef.current = true;
if (initialCloudRepository) return;
setWorkspaceModeState(lastUsedWorkspaceMode || "local");
}, [settingsHydrated, lastUsedWorkspaceMode, initialCloudRepository]);

const setWorkspaceMode = (mode: WorkspaceMode) => {
didResolveWorkspaceModeRef.current = true;
setWorkspaceModeState(mode);
setLastUsedWorkspaceMode(mode);
if (mode !== "cloud") {
Expand Down
Loading