Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(chat): persist preset selection across settings navigation (#4966)

Harsh Kumare65867769648
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-session-lifecycle.ts b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-session-lifecycle.ts
index 865ea0421..ba0121479 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-session-lifecycle.ts
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-session-lifecycle.ts
@@ -84,7 +84,19 @@ export function usePiSessionLifecycle({
const presets = aiPresets ?? [];
const fallback = presets.find((preset) => preset.defaultPreset) ?? presets[0];
setActivePreset((prev) => {
- if (!prev) return fallback;
+ if (!prev) {
+ // On fresh mount after a navigation (e.g. settings → home), restore
+ // the user's last-selected preset from localStorage instead of
+ // falling back to the default. localStorage is written by
+ // handleSetActivePreset on explicit user selection.
+ let savedId: string | null = null;
+ try { savedId = localStorage.getItem("chat-active-preset-id"); } catch {}
+ if (savedId) {
+ const saved = presets.find((preset) => preset.id === savedId);
+ if (saved) return saved;
+ }
+ return fallback;
+ }
const stillThere = presets.find((preset) => preset.id === prev.id);
if (stillThere) {
return stillThere.provider === prev.provider &&
diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
index 33dcdb0d9..baef6b5a1 100644
--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx
+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
@@ -212,6 +212,12 @@ export function StandaloneChat({
} else {
activePresetRef.current = preset;
setActivePreset(preset);
+ // Persist to localStorage so the preset survives full navigation
+ // (settings → home). Only for direct user selection, not the
+ // lifecycle fallback which uses the function form.
+ if (preset?.id) {
+ try { localStorage.setItem("chat-active-preset-id", preset.id); } catch {}
+ }
}
}, []);
const isStreamingRef = useRef(false);