Skip to content

fix(code): persist and restore native window zoom across reloads#2577

Open
richardsolomou wants to merge 2 commits into
mainfrom
posthog-code/persist-window-zoom
Open

fix(code): persist and restore native window zoom across reloads#2577
richardsolomou wants to merge 2 commits into
mainfrom
posthog-code/persist-window-zoom

Conversation

@richardsolomou

Copy link
Copy Markdown
Member

Problem

Native window zoom (Cmd +/−) reset to 100% intermittently while resizing. #2003 added crash-recovery auto-reload, so a renderer hiccup during resize reloads the webContents, and native zoom was never persisted or restored.

Changes

Persist zoomLevel in window-state and re-apply it on every did-finish-load. Replaced the native zoom menu roles with handlers that persist the level, so zoom survives reloads and restarts.

How did you test this?

Ran pnpm --filter code typecheck, Biome lint on the touched files, and check-host-boundaries.mjs, all pass. Did not manually verify zoom restore in a packaged build.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Native webContents zoom was never persisted, so it reset to 100% on every renderer reload. Since #2003 added crash-recovery auto-reload on recoverable renderer faults, a hiccup during window resize silently reloads and wipes the user's zoom.

Persist the zoom level in window-state and re-apply it on each did-finish-load, so it survives crash-recovery reloads, manual reloads, and app restarts. Replace the native zoom menu roles with handlers that persist the level.

Generated-By: PostHog Code
Task-Id: 548f3e3c-ef01-4627-b67c-2cf7d453b134
@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit f498b04.

@greptile-apps

greptile-apps Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/code/src/main/utils/zoom.ts:50-54
`adjustZoom` reads its baseline from `window.webContents.getZoomLevel()`, but Electron resets the webContents zoom to 0 the moment a reload begins (before `did-finish-load` fires to restore it). If the user presses Zoom In/Out during that reload window, the baseline is 0 rather than the persisted level, and the wrong value is then persisted — exactly the class of bug this PR aims to fix. Using `getSavedZoomLevel()` as the baseline makes the store the single source of truth and avoids the race.

```suggestion
// Adjust zoom by N steps and persist.
export function adjustZoom(window: ZoomableWindow, steps: number): void {
  if (window.isDestroyed()) return;
  setZoom(window, getSavedZoomLevel() + steps * ZOOM_STEP);
}
```

Reviews (1): Last reviewed commit: "fix(code): persist and restore native wi..." | Re-trigger Greptile

Comment thread apps/code/src/main/utils/zoom.ts Outdated
webContents zoom is reset to 0 during a reload, so reading it as the baseline for a zoom step could persist a wrong value if the user zooms mid-reload. Read the baseline from the persisted store instead, making it the single source of truth (matching applySavedZoom). Addresses PR review feedback.

Generated-By: PostHog Code
Task-Id: 548f3e3c-ef01-4627-b67c-2cf7d453b134
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant