@@ -130,12 +130,11 @@ const CLIENT_ROUTE_EXPORTS = [
130
130
"shouldRevalidate" ,
131
131
] ;
132
132
133
- // Each route gets its own virtual module marked with an entry query string
134
- const ROUTE_ENTRY_QUERY_STRING = "?route-entry=1" ;
135
-
136
- const isRouteEntry = ( id : string ) : boolean => {
137
- return id . endsWith ( ROUTE_ENTRY_QUERY_STRING ) ;
138
- } ;
133
+ /** This is used to manage a build optimization to remove unused route exports
134
+ from the client build output. This is important in cases where custom route
135
+ exports are only ever used on the server. Without this optimization we can't
136
+ tree-shake any unused custom exports because routes are entry points. */
137
+ const BUILD_CLIENT_ROUTE_QUERY_STRING = "?__react-router-build-client-route" ;
139
138
140
139
export type ServerBundleBuildConfig = {
141
140
routes : RouteManifest ;
@@ -207,7 +206,7 @@ const resolveChunk = (
207
206
path . relative ( ctx . rootDirectory , absoluteFilePath )
208
207
) ;
209
208
let entryChunk =
210
- viteManifest [ rootRelativeFilePath + ROUTE_ENTRY_QUERY_STRING ] ??
209
+ viteManifest [ rootRelativeFilePath + BUILD_CLIENT_ROUTE_QUERY_STRING ] ??
211
210
viteManifest [ rootRelativeFilePath ] ;
212
211
213
212
if ( ! entryChunk ) {
@@ -508,7 +507,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
508
507
resolveFileUrl (
509
508
ctx ,
510
509
resolveRelativeRouteFilePath ( route , ctx . reactRouterConfig )
511
- ) + ROUTE_ENTRY_QUERY_STRING
510
+ )
512
511
) } ;`;
513
512
} )
514
513
. join ( "\n" ) }
@@ -694,10 +693,10 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
694
693
caseSensitive : route . caseSensitive ,
695
694
module : combineURLs (
696
695
ctx . publicPath ,
697
- ` ${ resolveFileUrl (
696
+ resolveFileUrl (
698
697
ctx ,
699
698
resolveRelativeRouteFilePath ( route , ctx . reactRouterConfig )
700
- ) } ${ ROUTE_ENTRY_QUERY_STRING } `
699
+ )
701
700
) ,
702
701
hasAction : sourceExports . includes ( "action" ) ,
703
702
hasLoader : sourceExports . includes ( "loader" ) ,
@@ -886,7 +885,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
886
885
`${ path . resolve (
887
886
ctx . reactRouterConfig . appDirectory ,
888
887
route . file
889
- ) } ${ ROUTE_ENTRY_QUERY_STRING } `
888
+ ) } ${ BUILD_CLIENT_ROUTE_QUERY_STRING } `
890
889
) ,
891
890
] ,
892
891
} ,
@@ -1251,11 +1250,11 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
1251
1250
} ,
1252
1251
} ,
1253
1252
{
1254
- name : "react-router:route-entry " ,
1253
+ name : "react-router:build-client-route " ,
1255
1254
enforce : "pre" ,
1256
1255
async transform ( _code , id , options ) {
1257
- if ( ! isRouteEntry ( id ) ) return ;
1258
- let routeModuleId = id . replace ( ROUTE_ENTRY_QUERY_STRING , "" ) ;
1256
+ if ( ! id . endsWith ( BUILD_CLIENT_ROUTE_QUERY_STRING ) ) return ;
1257
+ let routeModuleId = id . replace ( BUILD_CLIENT_ROUTE_QUERY_STRING , "" ) ;
1259
1258
1260
1259
let routeFileName = path . basename ( routeModuleId ) ;
1261
1260
@@ -1516,10 +1515,6 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
1516
1515
let useFastRefresh = ! ssr && ( isJSX || code . includes ( devRuntime ) ) ;
1517
1516
if ( ! useFastRefresh ) return ;
1518
1517
1519
- if ( isRouteEntry ( id ) ) {
1520
- return { code : addRefreshWrapper ( ctx . reactRouterConfig , code , id ) } ;
1521
- }
1522
-
1523
1518
let result = await babel . transformAsync ( code , {
1524
1519
babelrc : false ,
1525
1520
configFile : false ,
@@ -1615,17 +1610,16 @@ function addRefreshWrapper(
1615
1610
id : string
1616
1611
) : string {
1617
1612
let route = getRoute ( reactRouterConfig , id ) ;
1618
- let acceptExports =
1619
- route || isRouteEntry ( id )
1620
- ? [
1621
- "clientAction" ,
1622
- "clientLoader" ,
1623
- "handle" ,
1624
- "meta" ,
1625
- "links" ,
1626
- "shouldRevalidate" ,
1627
- ]
1628
- : [ ] ;
1613
+ let acceptExports = route
1614
+ ? [
1615
+ "clientAction" ,
1616
+ "clientLoader" ,
1617
+ "handle" ,
1618
+ "meta" ,
1619
+ "links" ,
1620
+ "shouldRevalidate" ,
1621
+ ]
1622
+ : [ ] ;
1629
1623
return (
1630
1624
"\n\n" +
1631
1625
withCommentBoundaries (
0 commit comments