The page flashing on desktop and mobile (both preview and production) is caused by Vite HMR (Hot Module Replacement) constant reconnections.
-
server/vite.ts Line 59 (CANNOT AUTO-FIX - Protected File):
template = template.replace( `src="/src/main.tsx"`, `src="/src/main.tsx?v=${nanoid()}"`, );
This adds a random version to EVERY HTML request, forcing browser to reload constantly.
-
ErrorBoundary Auto-Retry Loop ✅ FIXED:
- Removed
setTimeout(resetErrorBoundary, 1000)infinite retry - Changed to manual reload button
- Removed
-
React StrictMode ✅ FIXED:
- Removed StrictMode wrapper causing double renders
✅ Removed infinite retry loop in client/src/App.tsx
- Before: Auto-retried every 1 second on module errors
- After: Shows manual reload button
✅ Removed React StrictMode in client/src/main.tsx
- Prevents double renders in development
File: server/vite.ts
Lines 55-61: Remove the nanoid() cache busting
Current Code:
// always reload the index.html file from disk incase it changes
let template = await fs.promises.readFile(clientTemplate, "utf-8");
template = template.replace(
`src="/src/main.tsx"`,
`src="/src/main.tsx?v=${nanoid()}"`,
);
const page = await vite.transformIndexHtml(url, template);Change To:
// always reload the index.html file from disk incase it changes
let template = await fs.promises.readFile(clientTemplate, "utf-8");
const page = await vite.transformIndexHtml(url, template);Simply delete lines 57-60 (the template.replace block).
In production builds, Vite HMR is automatically disabled. The flashing only happens in development mode.
To deploy:
- Fix the
.replitfile (remove extra port configs) - Run deployment
- Production build won't have HMR reconnections
Before Fix:
[vite] connecting...
[vite] server connection lost. Polling for restart...
[vite] connecting...
[vite] server connection lost. Polling for restart...
(Repeats constantly, causing flashing)
Expected After Full Fix:
[vite] connected.
(Stable connection, no flashing)
After modifying server/vite.ts:
- Save the file
- Server will auto-restart
- Refresh browser
- Page should load without flashing
- Check browser console - should see stable "[vite] connected."
- Development: Constant reconnections make the app unusable
- Production: Shouldn't have HMR at all (disabled in build)
- User Experience: Flashing creates poor first impression
Auto-Fixed ✅:
- Infinite retry loop removed
- StrictMode removed
- Error handling improved
Manual Fix Needed
- Edit
server/vite.tsto remove nanoid() cache busting (3 lines)
Alternative 🚀:
- Deploy to production where HMR is disabled by default
Generated: 2025-11-05