Skip to content

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

fix(client): auto-reload on stale chunk error in all browsers

Adam Eivy2b289e5cd05d
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index adb1a4539d..64a6e63fc1 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -20,3 +20,8 @@ A page-level run dock now slides up from the bottom of the Writers Room while im
- `STORYBOARD_TAB` enum now includes `OBJECTS` between `WORLD` and `SCENES`.
- `ANALYSIS_KINDS` server enum now includes `'objects'`.
- App selectors throughout the UI (task add form, OpenClaw) now list apps alphabetically by name via the shared `AppContextPicker`, instead of preserving the underlying storage order.
+
+## Fixed
+
+- Stale-chunk auto-reload now covers Safari ("Importing a module script failed") and Firefox ("error loading dynamically imported module") in addition to Chrome — previously iOS Safari users hit a "Something went wrong" error after a rebuild and had to tap Refresh manually. Detection is shared between `lazyWithReload` (the primary path) and `ErrorBoundary` (safety net), with a one-reload-per-session guard against infinite loops.
+- `ErrorBoundary` now uses theme-aware `text-port-text` / `text-port-text-muted` / `text-port-on-accent` instead of hardcoded `text-white` / `text-gray-400`, so the fallback UI is readable on light themes (Lumen Glass, etc).
diff --git a/client/src/App.jsx b/client/src/App.jsx
index 87d241cc1b..72954497ce 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -6,18 +6,14 @@ import BrailleSpinner from './components/BrailleSpinner';
import Dashboard from './pages/Dashboard';
import Apps from './pages/Apps';
import Ambient from './pages/Ambient';
+import { isStaleChunkError, reloadOnceForStaleChunk } from './utils/staleChunkReload';
-// Auto-reload on stale chunk errors (e.g., after a rebuild changes chunk hashes)
-// Uses sessionStorage to prevent infinite reload loops (max 1 reload per session)
+// Auto-reload on stale chunk errors (e.g., after a rebuild changes chunk hashes).
+// Detection covers Chrome / Firefox / Safari variants — see staleChunkReload.js.
const lazyWithReload = (importFn) => lazy(() =>
importFn().catch(err => {
- if (err.message?.includes('MIME type') || err.message?.includes('Failed to fetch dynamically imported module')) {
- const key = 'lazyReloadAttempted';
- if (!sessionStorage.getItem(key)) {
- sessionStorage.setItem(key, '1');
- window.location.reload();
- return new Promise(() => {}); // hang until reload completes
- }
+ if (isStaleChunkError(err) && reloadOnceForStaleChunk()) {
+ return new Promise(() => {}); // hang until reload completes
}
throw err;
})
diff --git a/client/src/components/ErrorBoundary.jsx b/client/src/components/ErrorBoundary.jsx
index d0a27ec245..f0f50a24ff 100644
--- a/client/src/components/ErrorBoundary.jsx
+++ b/client/src/components/ErrorBoundary.jsx
@@ -1,5 +1,6 @@
import { Component } from 'react';
import { AlertTriangle } from 'lucide-react';
+import { isStaleChunkError, reloadOnceForStaleChunk } from '../utils/staleChunkReload';
export default class ErrorBoundary extends Component {
constructor(props) {
@@ -12,6 +13,7 @@ export default class ErrorBoundary extends Component {
}
componentDidCatch(error, errorInfo) {
+ if (isStaleChunkError(error) && reloadOnceForStaleChunk()) return;
console.error(`💥 React Error: ${error.message}`, errorInfo);
}
@@ -23,8 +25,8 @@ export default class ErrorBoundary extends Component {
<div className="flex items-center justify-center mb-4">
<AlertTriangle size={32} className="text-port-error" />
</div>
- <h1 className="text-xl font-bold text-white text-center mb-2">Something went wrong</h1>
- <p className="text-gray-400 text-sm text-center mb-4">
+ <h1 className="text-xl font-bold text-port-text text-center mb-2">Something went wrong</h1>
+ <p className="text-port-text-muted text-sm text-center mb-4">
An unexpected error occurred. Please try refreshing the page.
</p>
{this.state.error && (
@@ -36,7 +38,7 @@ export default class ErrorBoundary extends Component {
)}
<button
onClick={() => window.location.reload()}
- className="w-full px-4 py-2 bg-port-accent hover:bg-port-accent/80 text-white rounded-lg transition-colors"
+ className="w-full px-4 py-2 bg-port-accent hover:bg-port-accent/80 text-port-on-accent rounded-lg transition-colors"
>
Refresh Page
</button>
diff --git a/client/src/utils/staleChunkReload.js b/client/src/utils/staleChunkReload.js
new file mode 100644
index 0000000000..3a09bf3d70
--- /dev/null
+++ b/client/src/utils/staleChunkReload.js
@@ -0,0 +1,31 @@
+// Cross-browser detection for stale dynamic-import chunk errors that happen
+// after a rebuild changes Vite chunk hashes while a tab is still open.
+//
+// Browser variants observed:
+// - Chrome: "Failed to fetch dynamically imported module"
+// - Firefox: "error loading dynamically imported module"
+// - Safari: "Importing a module script failed"
+// - Any browser when the new chunk's MIME type comes back wrong
+const STALE_CHUNK_PATTERNS = [
+ 'failed to fetch dynamically imported module',
+ 'error loading dynamically imported module',
+ 'importing a module script failed',
+ 'mime type'
+];
+
+const RELOAD_FLAG = 'portos.staleChunkReloadAttempted';
+
+export const isStaleChunkError = (err) => {
+ const msg = (err?.message || String(err || '')).toLowerCase();
+ return STALE_CHUNK_PATTERNS.some(p => msg.includes(p));
+};
+
+// Reloads once per session — sessionStorage guard prevents infinite loops if
+// the new bundle is also broken. Returns true if a reload was triggered.
+export const reloadOnceForStaleChunk = () => {
+ if (sessionStorage.getItem(RELOAD_FLAG)) return false;
+ sessionStorage.setItem(RELOAD_FLAG, '1');
+ console.warn('🔄 Stale chunk detected — reloading to pick up new bundle');
+ window.location.reload();
+ return true;
+};