From d5759e67a2f2183b911d16887107f9463aa44b93 Mon Sep 17 00:00:00 2001 From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com> Date: Tue, 10 Nov 2026 20:48:45 +0000 Subject: [PATCH 1/2] fix(browser): keep unsent page notes across restarts and ask before closing a tab that has them (#40851) * fix(browser): keep unsent page notes across restarts and ask before closing a tab that has them Unsent browser notes lived only in the renderer store and hydration reset them, so a reload, restart or tab close lost them. Each saved browser page now carries its unsent notes, hydration restores them, and every close path (tab strip, keyboard, CLI, phone) asks before discarding them. A page script's window.close() can't discard them. * fix(browser): keep tabs with unsent notes open on bulk close, like pinned tabs --- .../browser-page-window-close.test.ts | 15 +++- .../host-guest/browser-page-window-close.ts | 3 +- .../layout/close/PinnedTabCloseDialog.tsx | 55 ++++++++----- .../use-terminal-bulk-close-actions.ts | 8 +- .../ipc-events-close-routing-test-harness.ts | 1 + .../browser-request-ipc-bridge.owner.test.ts | 1 + .../ipc-events/browser-request-ipc-bridge.ts | 44 +++-------- .../browser-tab-close-with-reply.ts | 52 +++++++++++++ .../ipc-events/session-tab-ipc-bridge.ts | 7 +- src/renderer/src/i18n/locales/en.json | 5 +- .../workspace-session-browser-tabs.ts | 24 ++++-- .../persistence/workspace-session-patch.ts | 9 ++- .../persistence/workspace-session.ts | 5 +- .../workspace/tabs/workspace-tab-commands.ts | 9 ++- .../annotations/browser-page-annotation.ts | 13 ++++ ...browser-annotation-session-restore.test.ts | 76 ++++++++++++++++++ .../hydration/browser-hydration-state.ts | 23 ++++-- .../browser-workspace-doc-location.test.ts | 1 + .../tabs/closing/pinned-tab-close-guard.ts | 16 ++-- .../slices/tabs/pinned-tab-close-confirm.ts | 6 +- .../workspace-layout-frame-store-view.ts | 3 +- .../browser-page-annotation-schema.ts | 77 +++++++++++++++++++ .../languages/protected-copy-keys.json | 2 + .../workspace-session-browser-schema.ts | 5 +- .../workspace-session-state-types.ts | 6 +- 25 files changed, 374 insertions(+), 92 deletions(-) create mode 100644 src/renderer/src/hooks/ipc-events/browser-tab-close-with-reply.ts create mode 100644 src/renderer/src/store/slices/browser/hydration/browser-annotation-session-restore.test.ts create mode 100644 src/shared/browser/annotations/browser-page-annotation-schema.ts diff --git a/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.test.ts b/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.test.ts index 257250b024a..7f10e7912b4 100644 --- a/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.test.ts +++ b/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.test.ts @@ -12,9 +12,15 @@ vi.mock('@/lib/workspace/tabs/workspace-tab-commands', () => ({ import { handleGuestWindowCloseMessage } from './browser-page-window-close' import { BROWSER_GUEST_WINDOW_CLOSE_CHANNEL } from '../../../../../shared/browser-guest-window-close' -function seedTab(pageId: string, isPinned = false, siblingPageIds: string[] = []): void { +function seedTab( + pageId: string, + isPinned = false, + siblingPageIds: string[] = [], + browserAnnotationsByPageId: Record = {} +): void { storeState.value = { closeBrowserPage: closeBrowserPageMock, + browserAnnotationsByPageId, browserTabsByWorktree: { 'wt-1': [{ id: 'ws-1' }] }, browserPagesByWorkspace: { 'ws-1': [{ id: pageId }, ...siblingPageIds.map((id) => ({ id }))] }, unifiedTabsByWorktree: { @@ -40,6 +46,13 @@ describe('window.close() from a browser page', () => { expect(dispatchMock).not.toHaveBeenCalled() }) + it('never discards unsent notes', () => { + seedTab('page-n', false, [], { 'page-n': [{ id: 'note-1' }] }) + closeFrom('page-n', { back: false, forward: false }) + expect(dispatchMock).not.toHaveBeenCalled() + expect(closeBrowserPageMock).not.toHaveBeenCalled() + }) + it('closes only the calling page when its Orca tab holds other pages', () => { seedTab('page-e', false, ['page-sibling']) closeFrom('page-e', { back: false, forward: false }) diff --git a/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.ts b/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.ts index 452f602c2b1..5b37f60164e 100644 --- a/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.ts +++ b/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.ts @@ -32,7 +32,8 @@ export function handleGuestWindowCloseMessage( const tab = (state.unifiedTabsByWorktree[owner.worktreeId] ?? []).find( (candidate) => candidate.contentType === 'browser' && candidate.entityId === owner.workspaceId ) - if (tab?.isPinned) { + // A script may not discard what the user pinned or left unsent; the page's notes are all it closes. + if (tab?.isPinned || (state.browserAnnotationsByPageId[pageId]?.length ?? 0) > 0) { return } pagesOpenedByPage.delete(pageId) diff --git a/src/renderer/src/components/terminal-pane/layout/close/PinnedTabCloseDialog.tsx b/src/renderer/src/components/terminal-pane/layout/close/PinnedTabCloseDialog.tsx index 576c72f73ea..36b9280f7da 100644 --- a/src/renderer/src/components/terminal-pane/layout/close/PinnedTabCloseDialog.tsx +++ b/src/renderer/src/components/terminal-pane/layout/close/PinnedTabCloseDialog.tsx @@ -25,6 +25,7 @@ export default function PinnedTabCloseDialog(): React.JSX.Element { const [previousRequest, setPreviousRequest] = useState(request) const tabLabel = request?.tabLabel.trim() + const unsentNotes = request?.unsentNotes === true // Reset new requests before paint without reviving a cancelled request’s checkbox state. if (request !== previousRequest) { @@ -53,16 +54,26 @@ export default function PinnedTabCloseDialog(): React.JSX.Element { - {t( - 'auto.components.terminal.pane.PinnedTabCloseDialog.6c190f295a', - 'Close pinned tab?' - )} + {unsentNotes + ? t( + 'auto.components.terminal.pane.PinnedTabCloseDialog.unsent_notes_title', + 'Discard unsent notes?' + ) + : t( + 'auto.components.terminal.pane.PinnedTabCloseDialog.6c190f295a', + 'Close pinned tab?' + )} - {t( - 'auto.components.terminal.pane.PinnedTabCloseDialog.0d1963f4a6', - 'This tab is pinned. Are you sure you want to close it?' - )} + {unsentNotes + ? t( + 'auto.components.terminal.pane.PinnedTabCloseDialog.unsent_notes_description', + "This tab has notes you haven't sent. Closing it discards them." + ) + : t( + 'auto.components.terminal.pane.PinnedTabCloseDialog.0d1963f4a6', + 'This tab is pinned. Are you sure you want to close it?' + )} {tabLabel ? ( @@ -70,19 +81,21 @@ export default function PinnedTabCloseDialog(): React.JSX.Element { {tabLabel}

) : null} -
- setDontAskAgain(checked === true)} - /> - -
+ {unsentNotes ? null : ( +
+ setDontAskAgain(checked === true)} + /> + +
+ )} + + + + + {openLabel} + + + {expanded && ( + + + + )} +
+ {actions} +
+
+ {showSummaryRow && ( + + {branch && ( + + + + {branch} + )} - - {(branch || !!ahead || !!behind) && ( - - {branch && ( - - - {branch} - - )} - {!!ahead && ( - - - {ahead} - - )} - {!!behind && ( - - - {behind} + + {!expanded && } + {!expanded && changeCount > 0 && ( + + {t( + 'auto.components.rightSidebar.FolderWorkspaceSourceControl.changeCount', + '{{count}} changes', + { count: changeCount, defaultValue_one: '{{count}} change' } + )} )} - )} - - - - - - {openLabel} - + + )} ) } diff --git a/src/renderer/src/components/right-sidebar/source-control/listing/section-header.tsx b/src/renderer/src/components/right-sidebar/source-control/listing/section-header.tsx index e6b95041d57..00a38832642 100644 --- a/src/renderer/src/components/right-sidebar/source-control/listing/section-header.tsx +++ b/src/renderer/src/components/right-sidebar/source-control/listing/section-header.tsx @@ -3,6 +3,7 @@ import { ChevronDown } from 'lucide-react' import { cn } from '@/lib/class-names' import { Button } from '@/components/ui/button' import { useTranslate } from '@/i18n/use-translate' +import { useSourceControlScope } from '../panel/worktree-scope' export function SectionHeader({ label, @@ -23,22 +24,27 @@ export function SectionHeader({ actions?: React.ReactNode }): React.JSX.Element { const t = useTranslate() + // Folder cards keep the gap above the first file equal to the one below the last. + const compact = useSourceControlScope() !== null // Share the rounded container so hover styling spans the whole row. return ( -
+
-
{actions}
+
+ {actions} +
) diff --git a/src/renderer/src/components/right-sidebar/source-control/listing/uncommitted-sections.tsx b/src/renderer/src/components/right-sidebar/source-control/listing/uncommitted-sections.tsx index c80dea85b36..6c77ceaf81a 100644 --- a/src/renderer/src/components/right-sidebar/source-control/listing/uncommitted-sections.tsx +++ b/src/renderer/src/components/right-sidebar/source-control/listing/uncommitted-sections.tsx @@ -14,6 +14,7 @@ import { import { ActionButton } from './action-button' import { SectionHeader } from './section-header' import { SourceControlSectionFileList } from './section-file-list' +import { useSourceControlScope } from '../panel/worktree-scope' import { getSourceControlSectionViewAction, type SourceControlDisplaySection, @@ -89,6 +90,7 @@ export function SourceControlUncommittedSections(props: { requestDiscardEntry: (entry: GitStatusEntry) => void diffCommentCountByPath: Map }): React.JSX.Element { + const embedded = useSourceControlScope() !== null const t = useTranslate() return ( <> @@ -176,35 +178,37 @@ export function SourceControlUncommittedSections(props: { } /> {!isCollapsed && ( - +
+ +
)}
) diff --git a/src/renderer/src/components/right-sidebar/source-control/listing/use-selection.ts b/src/renderer/src/components/right-sidebar/source-control/listing/use-selection.ts index 9888f31b182..9cc0b17c0d0 100644 --- a/src/renderer/src/components/right-sidebar/source-control/listing/use-selection.ts +++ b/src/renderer/src/components/right-sidebar/source-control/listing/use-selection.ts @@ -190,7 +190,8 @@ export function useSourceControlSelection({ return } - const container = containerRef.current + const panel = containerRef.current + const container = panel?.closest('[data-source-control-worktree]') ?? panel const target = e.target if (!container || !(target instanceof Node) || container.contains(target)) { return diff --git a/src/renderer/src/components/right-sidebar/source-control/panel/branch-context-row.tsx b/src/renderer/src/components/right-sidebar/source-control/panel/branch-context-row.tsx index af4712d35a9..940a009f98c 100644 --- a/src/renderer/src/components/right-sidebar/source-control/panel/branch-context-row.tsx +++ b/src/renderer/src/components/right-sidebar/source-control/panel/branch-context-row.tsx @@ -103,6 +103,7 @@ export function SourceControlBranchContextRow({ headControl, manualReviewUrl, branchLineTotal, + reviewControl, onChangeBaseRef, onRetry }: { @@ -112,6 +113,7 @@ export function SourceControlBranchContextRow({ headControl?: React.ReactNode manualReviewUrl?: string | null branchLineTotal?: GitBranchLineTotal | null + reviewControl?: React.ReactNode onChangeBaseRef: () => void onRetry: () => void }): React.JSX.Element | null { @@ -124,8 +126,11 @@ export function SourceControlBranchContextRow({ return null } return ( -
- {headControl ?? } +
+ + {headControl ?? } + + {reviewControl}
) } @@ -159,7 +164,12 @@ export function SourceControlBranchContextRow({ onChangeBaseRef={onChangeBaseRef} changeBaseTitle={changeBaseTitle} leading={