-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Open
Description
Reproduction
CSS flash occurs when middleware throws a response while root route has a loader function. The ErrorBoundary content appears unstyled briefly before styled version loads.
Root Cause
Timing conflict between:
- Root route loader execution
- Child route middleware throwing response (e.g. 404)
This causes CSS styles to not be immediately available when ErrorBoundary renders.
Minimal Reproduction
StackBlitz: StackBlitz
Steps to Reproduce
- Visit the StackBlitz project
- Click "Go to Admin" link
- Observe the CSS flash: unstyled text appears briefly before styled error page
Workaround
Removing the loader from app/root.tsx
eliminates the CSS flash.
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 20.19.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@react-router/dev: ^7.8.0 => 7.8.0
@react-router/node: ^7.8.0 => 7.8.0
@react-router/serve: ^7.8.0 => 7.8.0
react-router: ^7.8.0 => 7.8.0
vite: ^6.3.3 => 6.3.5
Used Package Manager
npm
Expected Behavior
Error page should render with styles applied immediately, no flash of unstyled content.
Actual Behavior
Flash of unstyled content (FOUC): "Oops! Page Not Found." appears as plain text briefly before the ErrorBoundary renders with its intended styling.