fix(desktop): auto-open DevTools only for UI dev, not every unpacked run - #150
Open
Lumen Yang (LumenYoung) wants to merge 1 commit into
Open
fix(desktop): auto-open DevTools only for UI dev, not every unpacked run#150Lumen Yang (LumenYoung) wants to merge 1 commit into
Lumen Yang (LumenYoung) wants to merge 1 commit into
Conversation
DevTools auto-opened whenever the app was unpacked (IS_DEV = !app.isPackaged). That covers the intended case — UI development via 'dev:desktop' with Vite HMR — but also unintended ones: - 'start:desktop', whose name and semantics are 'build, then run the desktop app as a user would', yet it ends in DevTools popping up; - an unpacked production build run straight from source, e.g. when packaging is unavailable on the target machine. Both are consumption scenarios, not development scenarios, and losing the app window's first paint to DevTools is jarring. DevTools now auto-open only when either: - WEB_DEV_SERVER_URL is set — the exact signal that the renderer is being developed via Vite HMR (dev:desktop), so UI developers see no change; or - HUABU_DEVTOOLS=1 — explicit opt-out override for any other case. F12 / Ctrl+Shift+I still toggle DevTools at any time.
Lumen Yang (LumenYoung)
force-pushed
the
main
branch
from
September 1, 2026 14:57
a7fb5ed to
797071b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(desktop): auto-open DevTools only for UI dev, not every unpacked run
Summary
DevTools currently auto-open on every run of the desktop app that isn't a packaged build. This PR narrows that to the one scenario where auto-opening actually helps — renderer development with Vite HMR — and adds an explicit opt-out for everything else.
The problem
The trigger for auto-opening DevTools is
IS_DEV, which is defined as:!app.isPackagedmeans "not an electron-builder artifact" — but it does not mean "the user is developing the UI". Several legitimate, non-development ways of running Huabu fall into this bucket and get DevTools forced open at launch:pnpm start:desktop— the script's name and documented semantics are "build everything, then run the desktop app as a user would". Yet because it ends inpnpm --filter @huabu/desktop dev(which spawns an unpacked Electron), DevTools pop up. A start script shouldn't put a debugger in your face.An unpacked production build run straight from source. If someone builds the app (
pnpm run build:desktopsteps minuselectron-builder) and runselectron .directly — for example because packaging isn't available or fails on their platform — every launch opens DevTools. This is a consumption scenario, not a development scenario.Any other unpacked Electron invocation, such as CI smoke tests or sandbox-restricted environments that bypass electron-builder.
In all of these cases the main application window's first paint is immediately covered by DevTools, and the user has to close it by hand — every single launch.
What the behavior should be
Auto-opening DevTools is genuinely useful in exactly one situation: UI/renderer development, where you're iterating on the web frontend inside Electron and want the inspector available immediately. The desktop dev orchestrator (
pnpm dev:desktop) already has a precise, unambiguous signal for this: it setsWEB_DEV_SERVER_URLto hand the renderer to Vite with HMR.The fix
DevTools now auto-open only when either:
WEB_DEV_SERVER_URLis set — i.e. the renderer is being served by Vite via thedev:desktoporchestrator. UI developers see no change in behavior.HUABU_DEVTOOLS=1is set — an explicit override for anyone who wants the old behavior in any other unpacked scenario.F12 / Ctrl+Shift+I still toggle DevTools at any time (existing shortcut handling is untouched).
Behavior matrix
pnpm dev:desktop(Vite HMR, real UI dev)pnpm start:desktop(build, then run)electron .app.isPackaged)HUABU_DEVTOOLS=1Testing
tsc --noEmitpasses for@huabu/desktop.WEB_DEV_SERVER_URLrestores auto-open;HUABU_DEVTOOLS=1forces auto-open; F12 toggles as before.