From 156c53ecc82851c7703c72ccdea3ea25a6b1dfe8 Mon Sep 17 00:00:00 2001 From: seb Date: Sat, 8 Aug 2026 16:51:58 +0200 Subject: [PATCH] fix(vite): dedupe shared deps to avoid duplicate React from dashgui dashgui is a local symlinked package with its own nested node_modules containing a second copy of react/@mui/@emotion. Vite bundled that nested React into a dep chunk, causing 'Cannot read properties of null (reading 'useContext')' on routes rendering dashgui/MUI components. Dedupe forces these shared packages to resolve from dashfront's single tree. --- vite.config.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/vite.config.js b/vite.config.js index 59d2b24..29cf599 100644 --- a/vite.config.js +++ b/vite.config.js @@ -62,6 +62,29 @@ function hasRequestBody(method) { return method === 'POST' || method === 'PUT' || method === 'PATCH'; } +// dashgui is a local (symlinked) package with its own nested node_modules. +// Its nested react/@mui/@emotion copies would otherwise get bundled in, +// producing a duplicate React instance and "Cannot read properties of null +// (reading 'useContext')" at runtime. Dedupe forces these to resolve from +// dashfront's tree. (dashgui's own package.json "exports" map already points +// the dashgui/* subpaths at its src/, so no alias is needed.) +const sharedDeps = [ + 'react', + 'react-dom', + 'react/jsx-runtime', + 'react/jsx-dev-runtime', + 'react-router', + 'react-router-dom', + '@emotion/react', + '@emotion/styled', + '@mui/material', + '@mui/icons-material', +]; + +const sharedResolve = { + dedupe: sharedDeps, +}; + const sharedServer = { // HTTP :4209 — HTTPS :4308 (self-signed; see npm run cert / dev:https) port: useHttps ? 4308 : 4209, @@ -127,6 +150,7 @@ const sharedServer = { }; export default defineConfig(({ command }) => ({ + resolve: sharedResolve, build: { rolldownOptions: { output: {