File tree Expand file tree Collapse file tree 5 files changed +13
-10
lines changed
react-router-dev/vite/static Expand file tree Collapse file tree 5 files changed +13
-10
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " react-router " : patch
3
+ ---
4
+
5
+ In Framework Mode, clear critical CSS in development after initial render
Original file line number Diff line number Diff line change 113
113
- FilipJirsak
114
114
- focusotter
115
115
- foxscotch
116
+ - frodi-karlsson
116
117
- frontsideair
117
118
- fucancode
118
119
- fyzhu
Original file line number Diff line number Diff line change @@ -158,8 +158,6 @@ const routeUpdates = new Map();
158
158
window . __reactRouterRouteModuleUpdates = new Map ( ) ;
159
159
160
160
import . meta. hot . on ( "react-router:hmr" , async ( { route } ) => {
161
- window . __reactRouterClearCriticalCss ( ) ;
162
-
163
161
if ( route ) {
164
162
routeUpdates . set ( route . id , route ) ;
165
163
}
Original file line number Diff line number Diff line change @@ -229,19 +229,19 @@ export function HydratedRouter(props: HydratedRouterProps) {
229
229
} ) ;
230
230
}
231
231
232
- // Critical CSS can become stale after code changes, e.g. styles might be
233
- // removed from a component, but the styles will still be present in the
234
- // server HTML. This allows our HMR logic to clear the critical CSS state .
232
+ // We only want to show critical CSS in dev for the initial server render to
233
+ // avoid a flash of unstyled content. Once the client-side JS kicks in, we can
234
+ // clear it to avoid duplicate styles .
235
235
let [ criticalCss , setCriticalCss ] = React . useState (
236
236
process . env . NODE_ENV === "development"
237
237
? ssrInfo ?. context . criticalCss
238
238
: undefined
239
239
) ;
240
- if ( process . env . NODE_ENV === "development" ) {
241
- if ( ssrInfo ) {
242
- window . __reactRouterClearCriticalCss = ( ) => setCriticalCss ( undefined ) ;
240
+ React . useEffect ( ( ) => {
241
+ if ( process . env . NODE_ENV === "development" ) {
242
+ setCriticalCss ( undefined ) ;
243
243
}
244
- }
244
+ } , [ ] ) ;
245
245
246
246
let [ location , setLocation ] = React . useState ( router . state . location ) ;
247
247
Original file line number Diff line number Diff line change @@ -29,7 +29,6 @@ declare global {
29
29
var __reactRouterRouteModules : RouteModules | undefined ;
30
30
var __reactRouterDataRouter : DataRouter | undefined ;
31
31
var __reactRouterHdrActive : boolean ;
32
- var __reactRouterClearCriticalCss : ( ( ) => void ) | undefined ;
33
32
var $RefreshRuntime$ :
34
33
| {
35
34
performReactRefresh : ( ) => void ;
You can’t perform that action at this time.
0 commit comments