fix(desktop): keep dev renderer on one Vite dep-optimizer generation - #4782
Open
me2seeks wants to merge 1 commit into
Open
fix(desktop): keep dev renderer on one Vite dep-optimizer generation#4782me2seeks wants to merge 1 commit into
me2seeks wants to merge 1 commit into
Conversation
Opening Settings in a dev session could kill the renderer with "Cannot read properties of null (reading 'useRef')": the page executed two optimizer generations at once — react/react-dom chunks resurrected from the persistent Electron HTTP cache (immutable `?v=<browserHash>` entries whose per-dep labels survive re-optimization commits) next to freshly transformed sources importing today's react copy. Two React instances leave the hook dispatcher null on one of them, and the first hook call in any lazily loaded component crashes. - main-window: clear the session HTTP cache before loading a dev server (main-renderer-dev-cache.ts, packaged file:// builds untouched) - dev.mjs: warm the renderer entry and wait for the crawl to settle before launching Electron, so the initial optimizer commit lands before the window loads Fixes apache#4775 Generated-by: Maka
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.
Summary
In dev sessions, opening Settings (or any lazily loaded component that runs hooks) could crash the renderer with
TypeError: Cannot read properties of null (reading 'useRef'). The page was executing two React module instances: freshly transformed sources import the current generation'sreact.js, whilereact-domand several chunks were resurrected from the persistent Electron HTTP cache out of a previous Vite dep-optimizer generation. The dispatcher is only set on the instancereact-domrenders with; hooks called through the other instance seenulland throw.Two changes, both dev-only (packaged builds load
file://and are unaffected):main-renderer-dev-cache.ts(new): clear the session HTTP cache before loading a Vite dev server, so immutable?v=<browserHash>chunks from older generations can never be resurrected. Failure downgrades to a warning instead of blocking window creation. Wired intomain-window.tsright beforeloadMainRenderer.dev.mjs: afterserver.listen(), warm the renderer entry (warmupRequest('/main.tsx')) andwaitForRequestsIdle()before launching Electron, so the initial dependency crawl / optimizer commit lands before the window starts loading modules.Fixes #4775
Verification
tsc -p tsconfig.main.json --noEmit✓npm --workspace @maka/desktop run build:main✓node --test dist/main/__tests__/main-renderer-dev-cache.test.js— 3 pass (clears in dev / untouched for packaged / failure downgrades) ✓node --test scripts/dev-app-runtime.test.mjs✓biome checkon touched files ✓cacheDir):environments.client.warmupRequest('/main.tsx')+waitForRequestsIdle()settle in ~2.4s with the entry graph crawled and the dep optimizer bundling ✓npm test, e2e suites (heavier than this change; happy to run on request).Root cause
Evidence gathered on the affected machine (full write-up in #4775):
?v=browser hashes:react.js?v=3911c03d(current generation) vs.client-CwWlPFAR.js,ToastViewport-*.js,Layer-*.js,i18n-*.js,theme-*.jsall at?v=d164f9b2(a generation no longer on disk).~/.config/Maka Dev/Cache) held multiple historical generations, e.g. a cachedreact-dom_client.js?v=c163ffcewhose body importsclient-CwWlPFAR.js?v=d164f9b2, which importsreact.js?v=4a8fd6a8— an intact stale chunk graph, loadable forever thanks toCache-Control: immutable.node_modules/.vite/deps_temp_*leftovers show mid-session re-optimizations happen in this workspace (late-discovered deps), each rotatingbrowserHash.dev.mjslaunched Electron immediately afterserver.listen(); observed timings had the deps commit land at T+2.4s and the app ready at T+3.2s — page load raced the generation swap.AI use
Select exactly one:
Tool(s) and scope: Maka (AI agent) — reproduced the diagnosis from on-disk evidence (Vite optimizer metadata, Electron HTTP cache), authored the patch and its tests. Commit carries the
Generated-by: Makatrailer.Checklist
Does this PR entail a change in behavior?