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 113113- FilipJirsak
114114- focusotter
115115- foxscotch
116+ - frodi-karlsson
116117- frontsideair
117118- fucancode
118119- fyzhu
Original file line number Diff line number Diff line change @@ -158,8 +158,6 @@ const routeUpdates = new Map();
158158window . __reactRouterRouteModuleUpdates = new Map ( ) ;
159159
160160import . meta. hot . on ( "react-router:hmr" , async ( { route } ) => {
161- window . __reactRouterClearCriticalCss ( ) ;
162-
163161 if ( route ) {
164162 routeUpdates . set ( route . id , route ) ;
165163 }
Original file line number Diff line number Diff line change @@ -229,19 +229,19 @@ export function HydratedRouter(props: HydratedRouterProps) {
229229 } ) ;
230230 }
231231
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 .
235235 let [ criticalCss , setCriticalCss ] = React . useState (
236236 process . env . NODE_ENV === "development"
237237 ? ssrInfo ?. context . criticalCss
238238 : undefined
239239 ) ;
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 ) ;
243243 }
244- }
244+ } , [ ] ) ;
245245
246246 let [ location , setLocation ] = React . useState ( router . state . location ) ;
247247
Original file line number Diff line number Diff line change @@ -29,7 +29,6 @@ declare global {
2929 var __reactRouterRouteModules : RouteModules | undefined ;
3030 var __reactRouterDataRouter : DataRouter | undefined ;
3131 var __reactRouterHdrActive : boolean ;
32- var __reactRouterClearCriticalCss : ( ( ) => void ) | undefined ;
3332 var $RefreshRuntime$ :
3433 | {
3534 performReactRefresh : ( ) => void ;
You can’t perform that action at this time.
0 commit comments