Skip to content

fix(webview): prevent crash when game width is 0 - #2734

Merged
KochiyaOcean merged 1 commit into
masterfrom
fix/webview-zero-width
Oct 8, 2026
Merged

KochiyaOcean merged 1 commit into
masterfrom
fix/webview-zero-width

Conversation

@KochiyaOcean

Copy link
Copy Markdown
Member

Closes #2733

Problem

Setting the fixed game width to 0 in the display settings leaves poi with a black, unresponsive window, and since the value is saved to config it happens again on every launch.

The webview zoom factor is derived from the measured webview width, so a 0 width yields a zoom factor of 0. Electron's setZoomFactor requires a factor greater than 0; the call is made from a React effect in views/components/etc/webview.tsx.

Changes

  • views/components/etc/webview.tsx: skip the zoom sync (and forceSyncZoom) unless the factor is positive. This also covers a 0 width reached other ways, e.g. dragging the game area fully closed in non-fixed mode.
  • views/components/settings/display/resolution-config.tsx: ignore widths below MIN_WEBVIEW_WIDTH (100 px) and use it as the numeric input's minimum instead of 0.
  • views/services/layout.ts: on startup, reset a saved poi.webview.width / poi.webview.windowWidth below the minimum to 1200, so a config that already holds 0 recovers without manual editing.
  • views/services/utils.ts: add the shared MIN_WEBVIEW_WIDTH constant.

Testing

  • npm run lint:js on the touched files and npm run typecheck pass.
  • Not verified in a running app: the crash was not reproduced and the fix was not exercised manually. The cause is inferred from the code path.

🤖 Generated with Claude Code

Closes #2733

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 8, 2026 17:34
@KochiyaOcean
KochiyaOcean merged commit e38bdbc into master Oct 8, 2026
12 of 14 checks passed
@KochiyaOcean
KochiyaOcean deleted the fix/webview-zero-width branch October 8, 2026 17:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused validation and runtime guards consistently prevent zero-width zoom crashes.

0 open findings

What changed in this PR

Prevents invalid zero-width configurations from crashing Electron’s game webview.

Changes:

  • Enforces a shared 100 px minimum width.
  • Repairs invalid saved widths during startup.
  • Skips zoom synchronization for non-positive factors.
File Description
views/​services/​utils.ts Defines the shared minimum width.
views/​services/​layout.ts Resets invalid saved widths.
views/​components/​settings/​display/​resolution-config.tsx Rejects widths below the minimum.
views/​components/​etc/​webview.tsx Guards Electron zoom calls.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@petit-chiba petit-chiba Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review:

No actionable findings.

The change is internally consistent and closes the reported failure path: the non-positive factor is now rejected before both view.setZoomFactor(zoomFactor) calls (views/components/etc/webview.tsx:96 and :232), persisted sub-minimum widths are normalized to 1200 for both poi.webview.width and poi.webview.windowWidth (views/services/layout.ts:10-15, which runs before adjustSize() in the same module), and the settings handler plus the numeric input's minimum both use the shared MIN_WEBVIEW_WIDTH (views/components/settings/display/resolution-config.tsx:95,180). I could not construct a concrete, diff-introduced correctness, security, or reliability defect from these changes.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

I reviewed the 4-file diff on top of examining the full call chain (kan-game-wrapper.tsx, redux layout slice, env-parts/config wiring, and Electron 44's WebContents::SetZoomFactor, which literally throws 'zoomFactor' must be a double greater than 0.0 for factor ≤ epsilon). The core mechanism the PR targets is real, and the guard + config-reset + settings minimum are consistent with each other. Startup ordering also works out: services.ts imports create-store before services/layout, so the polyfill's config.set lands in the pre-created store and the webview re-renders at a positive width before the zoom effect matters.

Overall this is a well-scoped defensive fix. I found one concrete, reviewable issue plus a couple of items I checked and explicitly did not flag (wrong premise on Electron throwing — verified it does throw; the runtime non-fixed 0-width case being left black — that's inherent to a 0-width area, and the crash is now prevented).

Finding (1):

  • resolution-config.tsx silently accepts-and-shows sub-minimum values while rejecting the write, desyncing the controlled input from config. handleSetWebviewWidthWithDebounce calls setWidth(parseInt(...)) unconditionally (line 117) before handleSetWebviewWidth runs; with the new w < MIN_WEBVIEW_WIDTH early-return (line 95) the config write is skipped but the component state stays at the typed value (e.g. 0). The NumericInput is controlled by that width state and min does not constrain typed input on its own, so the field displays 0, the resolution label (labelText, line 147) shows 0%, and the hidden <option value={width}> (line 166) becomes the selected option — exactly the value this PR is meant to prevent — while the real config keeps the old width. This is new behavior introduced by the PR (previously a typed 0 was persisted). It doesn't crash, but it misleads the exact population this fix targets into believing the broken width was applied.
    • Smallest practical fix: in the rejection branch, normalize the UI instead of returning bare, e.g. if (isNaN(w) || w < MIN_WEBVIEW_WIDTH || !useFixed) { setWidth(Math.max(defaultWidthRef.current, MIN_WEBVIEW_WIDTH)); return } (or clamp width to MIN_WEBVIEW_WIDTH), so the displayed value and label always match what is actually stored.

Everything else checked out:

  • The zoomFactor > 0 guard (webview.tsx:96) is the correct invariant; Electron throws for factor ≤ epsilon, and NaN/undefined zoom levels are also now excluded.
  • The polyfill reset of poi.webview.windowWidth is safe — that key's only consumers default to 1200 and windowHeight is derived from it.
  • Importing MIN_WEBVIEW_WIDTH from views/services/utils into the settings component creates no new circular-init hazard: utils is already fully evaluated during create-store (via redux/layout), before layout.ts/resolution-config use it.

No security, permission, or CI concerns.

github run

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.

解析度0後黑屏

2 participants