Skip to content

The agent that grows with you

fix(desktop): a layout preview is saved only when Continue keeps it

alt-glitchd0aa08dbf9d0
diff --git a/apps/desktop/src/components/assistant-ui/theme-picker/look-preview.ts b/apps/desktop/src/components/assistant-ui/theme-picker/look-preview.ts
index 7da8059865e..54493490bbd 100644
--- a/apps/desktop/src/components/assistant-ui/theme-picker/look-preview.ts
+++ b/apps/desktop/src/components/assistant-ui/theme-picker/look-preview.ts
@@ -1,6 +1,6 @@
import { useEffect, useRef, useState } from 'react'
-import { snapshotChatLayout } from '@/components/onboarding/first-run/assembly'
+import { type PreviewUndo, snapshotChatLayout } from '@/components/onboarding/first-run/assembly'
import { applyDesktopLayoutPreset } from '@/store/pane-focus'
import { $accentOverride, setAccentOverride } from '@/themes/accent-override'
import { NOUS_ACCENT, resolveAccentPick } from '@/themes/accents'
@@ -12,7 +12,7 @@ export interface StagedLook {
interface LiveLook {
apply: (value: null | string, dark: boolean) => void
- snapshot: () => () => void
+ snapshot: () => PreviewUndo
}
// The accent previews through the unsaved override so nothing is persisted before Continue; the theme's own
@@ -22,7 +22,7 @@ const ACCENT: LiveLook = {
snapshot: () => {
const override = $accentOverride.get()
- return () => setAccentOverride(override)
+ return { keep: () => undefined, revert: () => setAccentOverride(override) }
}
}
@@ -46,7 +46,7 @@ interface PreviewOwner {
interface Baseline {
owners: Set<PreviewOwner>
- revert: () => void
+ undo: PreviewUndo
}
const baselines = new Map<LiveLook, Baseline>()
@@ -56,7 +56,7 @@ function release(live: LiveLook, owner: PreviewOwner): void {
if (baseline?.owners.delete(owner) && baseline.owners.size === 0) {
baselines.delete(live)
- baseline.revert()
+ baseline.undo.revert()
}
}
@@ -96,11 +96,12 @@ export function useLookPreview(kind: 'accent' | 'layout', dark: boolean): LookPr
// The sent value is the new truth: no open card puts the old one back.
if (settled.current) {
+ baselines.get(live)?.undo.keep()
baselines.delete(live)
}
},
stage: value => {
- const baseline = baselines.get(live) ?? { owners: new Set<PreviewOwner>(), revert: live.snapshot() }
+ const baseline = baselines.get(live) ?? { owners: new Set<PreviewOwner>(), undo: live.snapshot() }
baseline.owners.add(owner)
baselines.set(live, baseline)
diff --git a/apps/desktop/src/components/onboarding/first-run/assembly.ts b/apps/desktop/src/components/onboarding/first-run/assembly.ts
index b813ca07e14..5ebe5e39be3 100644
--- a/apps/desktop/src/components/onboarding/first-run/assembly.ts
+++ b/apps/desktop/src/components/onboarding/first-run/assembly.ts
@@ -25,12 +25,21 @@ import { $chatOnboardingSolo, $introView } from '@/store/onboarding-intro'
import { $paneStates, type PaneStateSnapshot } from '@/store/panes'
import { $activeSessionId, $selectedStoredSessionId } from '@/store/session'
-// The demo is borrowed: nothing it changes is persisted as the user's layout.
+// Layout previews open now; until Continue or cancel their arrangement stays in memory.
+let previews = 0
+
+// The demo and a preview are borrowed: nothing they change is persisted as the user's layout.
+function holdLayout(): void {
+ modeLayout.hold($chatOnboardingSolo.get() || previews > 0)
+}
+
$chatOnboardingSolo.subscribe(solo => {
- modeLayout.hold(solo)
+ holdLayout()
document.documentElement.toggleAttribute('data-onboarding-demo', solo)
})
+export const isLayoutPreviewing = (): boolean => previews > 0
+
export const $chatOnboardingThreadIds = atom<readonly string[]>([])
export const $chatLayoutPicked = atom(false)
@@ -150,9 +159,15 @@ export function assembleChatOnboarding(id: string, tree: LayoutNode, mode?: Inte
reconcileLayout(id, tree)
}
-/** A layout preview's undo: the arrangement it replaced. A preview never switches Simple/Advanced and
- * never ends the intro, so the arrangement is all there is to put back. */
-export function snapshotChatLayout(): () => void {
+/** Continue keeps a preview; leaving without it reverts. */
+export interface PreviewUndo {
+ keep: () => void
+ revert: () => void
+}
+
+/** A layout preview's undo. A preview never switches Simple/Advanced and never ends the intro, so the
+ * arrangement is all there is to put back; nothing is saved until Continue keeps it. */
+export function snapshotChatLayout(): PreviewUndo {
const snapshot = {
id: $activePresetId.get(),
panes: $paneStates.get(),
@@ -160,13 +175,29 @@ export function snapshotChatLayout(): () => void {
tree: $layoutTree.get()
}
- return () => {
- if (snapshot.tree) {
- $layoutTree.set(snapshot.tree)
- $paneStates.set(snapshot.panes)
- $userPlacedPanes.set(snapshot.placed)
- markActivePreset(snapshot.id)
- persistTree()
+ previews += 1
+ holdLayout()
+
+ const settle = () => {
+ previews -= 1
+ holdLayout()
+ }
+
+ return {
+ keep: () => {
+ settle()
+ modeLayout.flush()
+ },
+ // Settled after the restore, so the restore's own changes do not read as the user leaving the intro.
+ revert: () => {
+ if (snapshot.tree) {
+ $layoutTree.set(snapshot.tree)
+ $paneStates.set(snapshot.panes)
+ $userPlacedPanes.set(snapshot.placed)
+ markActivePreset(snapshot.id)
+ }
+
+ settle()
}
}
}
diff --git a/apps/desktop/src/components/onboarding/first-run/intro.ts b/apps/desktop/src/components/onboarding/first-run/intro.ts
index a7dca3d9abc..cfe9d57983e 100644
--- a/apps/desktop/src/components/onboarding/first-run/intro.ts
+++ b/apps/desktop/src/components/onboarding/first-run/intro.ts
@@ -9,7 +9,7 @@ import { $activeGatewayProfile } from '@/store/profile'
import { $selectedStoredSessionId } from '@/store/session'
import { retireTips } from '@/store/tips'
-import { $chatOnboardingThreadIds, endChatOnboardingSolo, keepChatOnboardingLayout } from './assembly'
+import { $chatOnboardingThreadIds, endChatOnboardingSolo, isLayoutPreviewing, keepChatOnboardingLayout } from './assembly'
/**
* The intro copy over an empty onboarding chat: it types centred (`playing`), springs up and waits at
@@ -100,7 +100,8 @@ function watchLeaveActions(): () => void {
const stops = [
() => window.removeEventListener(PANE_TOGGLE_REVEAL_EVENT, onReveal),
- $sidebarOpen.listen(() => leaveIntro()),
+ // A layout preview opens and closes the sidebar itself (Basic places it); only the user's toggle leaves.
+ $sidebarOpen.listen(() => !isLayoutPreviewing() && leaveIntro()),
$activeGatewayProfile.listen(profile => profile !== introProfile && leaveIntro()),
$selectedStoredSessionId.listen(id => (!id || !$chatOnboardingThreadIds.get().includes(id)) && leaveIntro())
]
diff --git a/apps/desktop/src/components/onboarding/first-run/layout.test.ts b/apps/desktop/src/components/onboarding/first-run/layout.test.ts
index 61ea8d9b13b..f5403db5168 100644
--- a/apps/desktop/src/components/onboarding/first-run/layout.test.ts
+++ b/apps/desktop/src/components/onboarding/first-run/layout.test.ts
@@ -6,9 +6,10 @@ import { applyLayoutPreset } from '@/components/pane-shell/tree/presets'
import { $activePresetId } from '@/components/pane-shell/tree/store'
import { applyAppearance } from '@/store/appearance-apply'
import { $interfaceMode, setInterfaceMode } from '@/store/interface-mode'
+import { $sidebarOpen, setSidebarOpen } from '@/store/layout'
import { $chatOnboardingSolo, $introView } from '@/store/onboarding-intro'
-import { openDemoLayout } from './assembly'
+import { openDemoLayout, snapshotChatLayout } from './assembly'
import { openIntro, skipIntro } from './intro'
const size = vi.fn()
@@ -44,6 +45,30 @@ describe('first-run layout beat', () => {
expect($activePresetId.get()).toBe('sidebar-left')
})
+ it('keeps the intro while a preview opens the sidebar itself', () => {
+ const undo = snapshotChatLayout()
+ setSidebarOpen(!$sidebarOpen.get())
+ undo.revert()
+
+ expect($introView.get()).toBe('intro')
+ })
+
+ it('saves a previewed layout only when Continue keeps it', () => {
+ skipIntro()
+ const writes = vi.spyOn(window.localStorage, 'setItem')
+
+ const cancelled = snapshotChatLayout()
+ applyLayoutPreset('picked', group(['workspace']))
+ cancelled.revert()
+ expect(writes).not.toHaveBeenCalled()
+
+ const kept = snapshotChatLayout()
+ applyLayoutPreset('picked', group(['workspace']))
+ kept.keep()
+ expect(writes).toHaveBeenCalled()
+ writes.mockRestore()
+ })
+
it('sizes the window normal on Skip setup', () => {
skipIntro()
diff --git a/apps/desktop/src/lib/layout-persistence.ts b/apps/desktop/src/lib/layout-persistence.ts
index 2c94b4b18fb..48da99b76cd 100644
--- a/apps/desktop/src/lib/layout-persistence.ts
+++ b/apps/desktop/src/lib/layout-persistence.ts
@@ -146,6 +146,10 @@ export function createLayoutPersistence(initialMode: InterfaceMode, persistent:
hold(next: boolean) {
held = next
},
+ /** Write every value as it is now, so a change made while held is kept. */
+ flush() {
+ entries.forEach(entry => entry.capture())
+ },
has(key: string) {
return snapshots.has(keyFor(key))
},