Skip to content
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
79 changes: 79 additions & 0 deletions src/main/window/createMainWindow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,85 @@ describe('createMainWindow', () => {
expect(browserWindowInstance.setSize).toHaveBeenCalledTimes(setSizeCalls)
})

it('runs a full repaint when the renderer relays a genuine window reveal (STA-2383)', () => {
vi.useFakeTimers()
const windowHandlers = new Map<string, ((...args: any[]) => void)[]>()
let windowSize: [number, number] = [1200, 800]
const webContents = {
on: vi.fn(),
setZoomLevel: vi.fn(),
setBackgroundThrottling: vi.fn(),
invalidate: vi.fn(),
isDestroyed: vi.fn(() => false),
setWindowOpenHandler: vi.fn(),
send: vi.fn(),
isDevToolsOpened: vi.fn(),
openDevTools: vi.fn(),
closeDevTools: vi.fn()
}
const browserWindowInstance = {
webContents,
on: vi.fn((event: string, handler: (...args: any[]) => void) => {
const handlers = windowHandlers.get(event) ?? []
handlers.push(handler)
windowHandlers.set(event, handlers)
}),
isDestroyed: vi.fn(() => false),
isMaximized: vi.fn(() => false),
isFullScreen: vi.fn(() => false),
getSize: vi.fn(() => windowSize),
setSize: vi.fn((width: number, height: number) => {
windowSize = [width, height]
}),
maximize: vi.fn(),
show: vi.fn(),
loadFile: vi.fn(),
loadURL: vi.fn()
}
browserWindowMock.mockImplementation(function () {
return browserWindowInstance
})

withPlatform('darwin', () => createMainWindow(null))

const revealHandler = vi
.mocked(ipcMain.on)
.mock.calls.find(([channel]) => channel === 'ui:window-revealed')?.[1]
expect(revealHandler).toBeTypeOf('function')

// Why: a reveal relayed by another window's webContents must not repaint this one.
revealHandler?.({ sender: {} } as never)
expect(browserWindowInstance.setSize).not.toHaveBeenCalled()
expect(webContents.invalidate).not.toHaveBeenCalled()

// The genuine reveal (matching sender) runs the full repaint: invalidate + the size jiggle
// that recomputes the stale dvh layout — the recovery bare focus/invalidate misses.
revealHandler?.({ sender: webContents } as never)
expect(webContents.invalidate).toHaveBeenCalledTimes(1)
// Why: the nudge is deferred off the event dispatch turn.
expect(browserWindowInstance.setSize).not.toHaveBeenCalled()
vi.advanceTimersByTime(0)
expect(browserWindowInstance.setSize).toHaveBeenNthCalledWith(1, 1201, 800)
vi.advanceTimersByTime(32)
expect(browserWindowInstance.setSize).toHaveBeenNthCalledWith(2, 1200, 800)

// Repeated reveal signals while a jiggle is active repaint but do not multiply terminal resizes.
revealHandler?.({ sender: webContents } as never)
revealHandler?.({ sender: webContents } as never)
expect(webContents.invalidate).toHaveBeenCalledTimes(3)
vi.advanceTimersByTime(0)
expect(browserWindowInstance.setSize).toHaveBeenNthCalledWith(3, 1201, 800)
expect(browserWindowInstance.setSize).toHaveBeenCalledTimes(3)

// A user resize that lands during the jiggle must not be rolled back to stale bounds.
windowSize = [1400, 900]
vi.advanceTimersByTime(32)
expect(browserWindowInstance.setSize).toHaveBeenCalledTimes(3)

windowHandlers.get('closed')?.[0]?.()
expect(ipcMain.removeListener).toHaveBeenCalledWith('ui:window-revealed', revealHandler)
})

it('repaints without the size nudge on macOS 26+ where re-entrant frame updates can deadlock AppKit', () => {
vi.useFakeTimers()
macosTahoeMock.value = true
Expand Down
28 changes: 25 additions & 3 deletions src/main/window/createMainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ function forceRepaint(window: BrowserWindow): void {
window.setSize(width + 1, height)
setTimeout(() => {
if (!window.isDestroyed()) {
window.setSize(width, height)
const [currentWidth, currentHeight] = window.getSize()
// Why: a real user resize during the jiggle owns the final bounds.
if (currentWidth === width + 1 && currentHeight === height) {
window.setSize(width, height)
}
}
activeRepaintJiggles.delete(window)
}, 32)
Expand All @@ -105,15 +109,33 @@ function installMacosVisibilityRepaint(window: BrowserWindow): void {
}
}

// Why (STA-2383): occlusion-uncover fires no restore/show, so the renderer relays its genuine
// hidden→visible reveal instead. Unlike a bare focus (every Cmd+Tab, window never hidden), this
// only fires when the window was actually occluded/throttled — exactly when the stale dvh layout
// stranded the bottom status bar off-screen — so the full repaint's size jiggle is warranted.
const onRendererRevealed = (event: Electron.IpcMainEvent): void => {
if (window.isDestroyed() || window.webContents.isDestroyed()) {
return
}
if (event.sender !== window.webContents) {
return
}
forceRepaint(window)
}
ipcMain.on('ui:window-revealed', onRendererRevealed)

window.on('restore', repaintAfterVisibilityTransition)
window.on('show', repaintAfterVisibilityTransition)
// Why: occlusion-uncover fires no restore/show, only focus; invalidate only — the setSize jiggle would SIGWINCH every terminal on Cmd+Tab.
// Why: occlusion-uncover fires no restore/show, only focus; invalidate only — the setSize jiggle would SIGWINCH every terminal on Cmd+Tab. The renderer-reveal relay above covers the stale-layout recovery that invalidate alone misses.
window.on('focus', () => {
if (!window.isDestroyed() && !window.webContents.isDestroyed()) {
window.webContents.invalidate()
}
})
window.on('closed', clearDelayedRepaint)
window.on('closed', () => {
clearDelayedRepaint()
ipcMain.removeListener('ui:window-revealed', onRendererRevealed)
})
}

function isMacAppPasteInput(input: Electron.Input): boolean {
Expand Down
1 change: 1 addition & 0 deletions src/preload/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3052,6 +3052,7 @@ export type PreloadApi = {
popupMenu: () => void
onWindowCloseRequested: (callback: (data: { isQuitting: boolean }) => void) => () => void
confirmWindowClose: () => void
notifyWindowRevealed: () => void
}
runtime: {
syncWindowGraph: (graph: RuntimeSyncWindowGraph) => Promise<RuntimeSyncWindowGraphResult>
Expand Down
4 changes: 4 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3877,6 +3877,10 @@ const api = {
/** Tell the main process to proceed with the window close. */
confirmWindowClose: (): void => {
ipcRenderer.send('window:confirm-close')
},
/** Report a genuine hidden→visible reveal so main can recover a stale (throttled) layout/compositor surface. */
notifyWindowRevealed: (): void => {
ipcRenderer.send('ui:window-revealed')
}
} satisfies PreloadApi['ui'],

Expand Down
18 changes: 18 additions & 0 deletions src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,24 @@ function App(): React.JSX.Element {
return () => document.removeEventListener('visibilitychange', handler)
}, [actions])

// Why (STA-2383): macOS throttles the backgrounded window; on occlusion-uncover only `focus`
// fires (invalidate-only), so the app-shell's dvh height stays stale and the bottom status bar
// is clipped off-screen until a manual resize. Relay the genuine hidden→visible reveal so main
// runs the same full repaint (size jiggle) that show/restore/resume get, recomputing the layout.
useEffect(() => {
if (!isMac || isPairedWebClientWindow()) {
return
}
const handler = (): void => {
if (document.visibilityState !== 'visible') {
return
}
window.api?.ui?.notifyWindowRevealed?.()
}
document.addEventListener('visibilitychange', handler)
return () => document.removeEventListener('visibilitychange', handler)
}, [])

const hasTabBar = tabCount >= 2
const showTitlebarExpandButton = workspaceChromeActive && !hasTabBar && effectiveActiveTabExpanded
// Activity/Space are full-page navigation surfaces (like Settings), so the worktree sidebar is hidden there.
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/web/web-preload-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2610,7 +2610,8 @@ function createWebUiApi(): NonNullable<Partial<PreloadApi>['ui']> {
requestClose: () => {},
popupMenu: () => {},
onWindowCloseRequested: () => noopUnsubscribe,
confirmWindowClose: () => {}
confirmWindowClose: () => {},
notifyWindowRevealed: () => {}
}
}

Expand Down
Loading