Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix(spa): prevent MIME type error on stale lazy-loaded chunks
Adam Eivy65a45d5e5d89
diff --git a/client/src/App.jsx b/client/src/App.jsxindex 70878ed3a5..e7960c623b 100644--- a/client/src/App.jsx+++ b/client/src/App.jsx@@ -21,18 +21,29 @@ import Insights from './pages/Insights';import Instances from './pages/Instances';import MeatSpace from './pages/MeatSpace';+// Auto-reload on stale chunk errors (e.g., after a rebuild changes chunk hashes)+const lazyWithReload = (importFn) => lazy(() =>+ importFn().catch(err => {+ if (err.message?.includes('MIME type') || err.message?.includes('Failed to fetch dynamically imported module')) {+ window.location.reload();+ return new Promise(() => {}); // hang until reload completes+ }+ throw err;+ })+);+// Lazy load heavier pages for code splitting// DevTools pages are large (~2300 lines total) so lazy load them-const AIProviders = lazy(() => import('./pages/AIProviders'));-const HistoryPage = lazy(() => import('./pages/DevTools').then(m => ({ default: m.HistoryPage })));-const RunsHistoryPage = lazy(() => import('./pages/DevTools').then(m => ({ default: m.RunsHistoryPage })));-const RunnerPage = lazy(() => import('./pages/DevTools').then(m => ({ default: m.RunnerPage })));-const UsagePage = lazy(() => import('./pages/DevTools').then(m => ({ default: m.UsagePage })));-const ProcessesPage = lazy(() => import('./pages/DevTools').then(m => ({ default: m.ProcessesPage })));-const AgentsPage = lazy(() => import('./pages/DevTools').then(m => ({ default: m.AgentsPage })));-const GitHub = lazy(() => import('./pages/GitHub'));-const CyberCity = lazy(() => import('./pages/CyberCity'));-const AppDetail = lazy(() => import('./pages/AppDetail'));+const AIProviders = lazyWithReload(() => import('./pages/AIProviders'));+const HistoryPage = lazyWithReload(() => import('./pages/DevTools').then(m => ({ default: m.HistoryPage })));+const RunsHistoryPage = lazyWithReload(() => import('./pages/DevTools').then(m => ({ default: m.RunsHistoryPage })));+const RunnerPage = lazyWithReload(() => import('./pages/DevTools').then(m => ({ default: m.RunnerPage })));+const UsagePage = lazyWithReload(() => import('./pages/DevTools').then(m => ({ default: m.UsagePage })));+const ProcessesPage = lazyWithReload(() => import('./pages/DevTools').then(m => ({ default: m.ProcessesPage })));+const AgentsPage = lazyWithReload(() => import('./pages/DevTools').then(m => ({ default: m.AgentsPage })));+const GitHub = lazyWithReload(() => import('./pages/GitHub'));+const CyberCity = lazyWithReload(() => import('./pages/CyberCity'));+const AppDetail = lazyWithReload(() => import('./pages/AppDetail'));// Loading fallback for lazy-loaded pagesconst PageLoader = () => (diff --git a/server/index.js b/server/index.jsindex c978b48a79..fc3c732256 100644--- a/server/index.js+++ b/server/index.js@@ -303,8 +303,13 @@ startUpdateScheduler();const CLIENT_DIST = join(__dirname, '..', 'client', 'dist');if (existsSync(CLIENT_DIST)) {app.use(express.static(CLIENT_DIST));- // SPA fallback: serve index.html for non-API routes- app.get('/{*splat}', (req, res) => {+ // SPA fallback: serve index.html for page navigations only+ // Skip asset requests (.js, .css, etc.) so stale chunk requests get a proper 404+ // instead of index.html with text/html MIME type+ app.get('/{*splat}', (req, res, next) => {+ if (req.path.match(/\.\w+$/) && !req.path.endsWith('.html')) {+ return next();+ }res.sendFile(join(CLIENT_DIST, 'index.html'));});console.log(`📦 Serving built UI from client/dist`);