The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): preview tab menu reads the live pin state so Pin toggles back to Unpin
teknium1f3747bc1e799
diff --git a/apps/desktop/src/app/chat/preview-tab-pin-menu.test.tsx b/apps/desktop/src/app/chat/preview-tab-pin-menu.test.tsxnew file mode 100644index 00000000000..f59c5cbffa0--- /dev/null+++ b/apps/desktop/src/app/chat/preview-tab-pin-menu.test.tsx@@ -0,0 +1,78 @@+import { cleanup, fireEvent, render, screen } from '@testing-library/react'+import type { ReactNode } from 'react'+import { afterEach, beforeAll, expect, it, vi } from 'vitest'++vi.mock('./right-rail/preview', () => ({+ PreviewTilePane: () => null+}))++vi.mock('./right-rail/preview-console-store', () => ({+ forgetPreviewConsole: () => undefined+}))++import type { MenuKit } from '@/components/ui/actions-menu'+import { registry } from '@/contrib/registry'+import { $previewTabs, closeRightRail, openPreview } from '@/store/preview'++import { watchPreviewTiles } from './preview-tile'++// The zone menu calls the registered pane's `tabMenuPrefix(kit)` each time it+// opens. A stand-in kit renders each row as a button so a click reaches the+// same `onSelect` the native menu fires.+const Item = ({ children, onSelect }: { children?: ReactNode; onSelect?: (event: Event) => void }) => (+ <button onClick={() => onSelect?.(new Event('select'))} type="button">+ {children}+ </button>+)++const Passthrough = ({ children }: { children?: ReactNode }) => <>{children}</>++const kit = {+ copyAppearance: 'menu-item',+ Item,+ Label: Passthrough,+ Separator: () => null,+ Sub: Passthrough,+ SubContent: Passthrough,+ SubTrigger: Passthrough+} as unknown as MenuKit++beforeAll(() => {+ watchPreviewTiles()+})++afterEach(() => {+ cleanup()+ closeRightRail()+})++/** Open the zone menu for `tabId` the way the strip does, click the pin row,+ * and close the menu again. Returns the label the row offered. */+function clickPinRow(tabId: string): string {+ const pane = registry.getArea('panes').find(entry => entry.id === `preview-tile:${tabId}`)+ const prefix = (pane?.data as { tabMenuPrefix?: (kit: MenuKit) => ReactNode } | undefined)?.tabMenuPrefix++ render(<>{prefix?.(kit)}</>)+ const row = screen.getByRole('button', { name: /pin/i })+ const label = row.textContent ?? ''++ fireEvent.click(row)+ cleanup()++ return label+}++it('offers Unpin after a pin and Pin after an unpin, toggling the stored flag each time', () => {+ openPreview({ kind: 'url', label: 'Browser', source: 'https://example.com', url: 'https://example.com' })+ const tabId = $previewTabs.get()[0]!.id+ const pinned = () => $previewTabs.get().find(tab => tab.id === tabId)?.pinned++ expect(clickPinRow(tabId)).toBe('Pin to workspace')+ expect(pinned()).toBe(true)++ expect(clickPinRow(tabId)).toBe('Unpin from workspace')+ expect(pinned()).toBe(false)++ expect(clickPinRow(tabId)).toBe('Pin to workspace')+ expect(pinned()).toBe(true)+})diff --git a/apps/desktop/src/app/chat/preview-tile.tsx b/apps/desktop/src/app/chat/preview-tile.tsxindex e46c755c336..01459c81e65 100644--- a/apps/desktop/src/app/chat/preview-tile.tsx+++ b/apps/desktop/src/app/chat/preview-tile.tsx@@ -103,20 +103,29 @@ function browserTabMenuPrefix(tabId: string) {* cross-session workspace, everything else belongs to the session that* opened it (#73890). URL tabs keep their browser rows below it. */function previewTabMenuPrefix(tabId: string) {- const pinned = Boolean($previewTabs.get().find(tab => tab.id === tabId)?.pinned)const browserRows = browserTabMenuPrefix(tabId)- return (kit: MenuKit) => (- <>- {renderActionItem(kit, {- icon: pinned ? 'pinned' : 'pin',- key: 'pin',- label: translateNow(pinned ? 'preview.unpin' : 'preview.pin'),- onSelect: () => setPreviewTabPinned(tabId, !pinned)- })}- {browserRows?.(kit) ?? null}- </>- )+ // Pin state is read when the menu renders and again on select, never at+ // registration: the mirror keeps a same-title registration (and so this+ // closure) for the tab's whole life, so a captured flag goes stale after the+ // first toggle and the row keeps offering — and re-applying — the same pin.+ const isPinned = () => Boolean($previewTabs.get().find(tab => tab.id === tabId)?.pinned)++ return (kit: MenuKit) => {+ const pinned = isPinned()++ return (+ <>+ {renderActionItem(kit, {+ icon: pinned ? 'pinned' : 'pin',+ key: 'pin',+ label: translateNow(pinned ? 'preview.unpin' : 'preview.pin'),+ onSelect: () => setPreviewTabPinned(tabId, !isPinned())+ })}+ {browserRows?.(kit) ?? null}+ </>+ )+ }}/** Tab title. A URL tab is titled by the CONTRIBUTION as the surface — see