1+ import * as React from 'react' ;
2+ import { createRootRoute } from '@tanstack/react-router' ;
3+ export const Route = createRootRoute ( {
4+ component : RootComponent
5+ } ) ;
6+ function RootComponent ( ) {
7+ return < div > Hello</ div > ;
8+ }
9+ const hot = import . meta. hot ;
10+ if ( hot && typeof window !== 'undefined' ) {
11+ hot . data ??= { } ;
12+ const tsrReactRefresh = window . __TSR_REACT_REFRESH__ ??= ( ( ) => {
13+ const ignoredExportsById = new Map ( ) ;
14+ const previousGetIgnoredExports = window . __getReactRefreshIgnoredExports ;
15+ window . __getReactRefreshIgnoredExports = ctx => {
16+ const ignoredExports = previousGetIgnoredExports ?.( ctx ) ?? [ ] ;
17+ const moduleIgnored = ignoredExportsById . get ( ctx . id ) ?? [ ] ;
18+ return [ ...ignoredExports , ...moduleIgnored ] ;
19+ } ;
20+ return {
21+ ignoredExportsById
22+ } ;
23+ } ) ( ) ;
24+ tsrReactRefresh . ignoredExportsById . set ( "createRootRoute.tsx" , [ 'Route' ] ) ;
25+ }
26+ export function TSRFastRefreshAnchor ( ) {
27+ return null ;
28+ }
29+ if ( import . meta. hot ) {
30+ const hot = import . meta. hot ;
31+ const hotData = hot . data ??= { } ;
32+ hot . accept ( newModule => {
33+ if ( Route && newModule && newModule . Route ) {
34+ const routeId = hotData [ 'tsr-route-id' ] ?? Route . id ;
35+ if ( routeId ) {
36+ hotData [ 'tsr-route-id' ] = routeId ;
37+ }
38+ ( function handleRouteUpdate ( routeId , newRoute ) {
39+ const router = window . __TSR_ROUTER__ ;
40+ const oldRoute = router . routesById [ routeId ] ;
41+ if ( ! oldRoute ) {
42+ return ;
43+ }
44+ ;
45+ const removedKeys = new Set ( ) ;
46+ Object . keys ( oldRoute . options ) . forEach ( key => {
47+ if ( ! ( key in newRoute . options ) ) {
48+ removedKeys . add ( key ) ;
49+ delete oldRoute . options [ key ] ;
50+ }
51+ } ) ;
52+ const oldHasShellComponent = "shellComponent" in oldRoute . options ;
53+ const newHasShellComponent = "shellComponent" in newRoute . options ;
54+ const preserveComponentIdentity = oldHasShellComponent === newHasShellComponent ;
55+ const componentKeys = [ "component" , "shellComponent" , "pendingComponent" , "errorComponent" , "notFoundComponent" ] ;
56+ if ( preserveComponentIdentity ) {
57+ componentKeys . forEach ( key => {
58+ if ( key in oldRoute . options && key in newRoute . options ) {
59+ newRoute . options [ key ] = oldRoute . options [ key ] ;
60+ }
61+ } ) ;
62+ }
63+ ;
64+ oldRoute . options = newRoute . options ;
65+ oldRoute . update ( newRoute . options ) ;
66+ oldRoute . _componentsPromise = undefined ;
67+ oldRoute . _lazyPromise = undefined ;
68+ router . routesById [ oldRoute . id ] = oldRoute ;
69+ router . routesByPath [ oldRoute . fullPath ] = oldRoute ;
70+ router . processedTree . matchCache . clear ( ) ;
71+ router . processedTree . flatCache ?. clear ( ) ;
72+ router . processedTree . singleCache . clear ( ) ;
73+ router . resolvePathCache . clear ( ) ;
74+ walkReplaceSegmentTree ( oldRoute , router . processedTree . segmentTree ) ;
75+ const filter = m => m . routeId === oldRoute . id ;
76+ const activeMatch = router . stores . matches . get ( ) . find ( filter ) ;
77+ const pendingMatch = router . stores . pendingMatches . get ( ) . find ( filter ) ;
78+ const cachedMatches = router . stores . cachedMatches . get ( ) . filter ( filter ) ;
79+ if ( activeMatch || pendingMatch || cachedMatches . length > 0 ) {
80+ if ( removedKeys . has ( "loader" ) || removedKeys . has ( "beforeLoad" ) ) {
81+ const matchIds = [ activeMatch ?. id , pendingMatch ?. id , ...cachedMatches . map ( match => match . id ) ] . filter ( Boolean ) ;
82+ router . batch ( ( ) => {
83+ for ( const matchId of matchIds ) {
84+ const store = router . stores . pendingMatchStores . get ( matchId ) || router . stores . matchStores . get ( matchId ) || router . stores . cachedMatchStores . get ( matchId ) ;
85+ if ( store ) {
86+ store . set ( prev => {
87+ const next = {
88+ ...prev
89+ } ;
90+ if ( removedKeys . has ( "loader" ) ) {
91+ next . loaderData = undefined ;
92+ }
93+ ;
94+ if ( removedKeys . has ( "beforeLoad" ) ) {
95+ next . __beforeLoadContext = undefined ;
96+ next . context = rebuildMatchContextWithoutBeforeLoad ( next ) ;
97+ }
98+ ;
99+ return next ;
100+ } ) ;
101+ }
102+ }
103+ } ) ;
104+ }
105+ ;
106+ router . invalidate ( {
107+ filter,
108+ sync : true
109+ } ) ;
110+ }
111+ ;
112+ function walkReplaceSegmentTree ( route , node ) {
113+ if ( node . route ?. id === route . id ) node . route = route ;
114+ if ( node . index ) walkReplaceSegmentTree ( route , node . index ) ;
115+ node . static ?. forEach ( child => walkReplaceSegmentTree ( route , child ) ) ;
116+ node . staticInsensitive ?. forEach ( child => walkReplaceSegmentTree ( route , child ) ) ;
117+ node . dynamic ?. forEach ( child => walkReplaceSegmentTree ( route , child ) ) ;
118+ node . optional ?. forEach ( child => walkReplaceSegmentTree ( route , child ) ) ;
119+ node . wildcard ?. forEach ( child => walkReplaceSegmentTree ( route , child ) ) ;
120+ }
121+ function getStoreMatch ( matchId ) {
122+ return router . stores . pendingMatchStores . get ( matchId ) ?. get ( ) || router . stores . matchStores . get ( matchId ) ?. get ( ) || router . stores . cachedMatchStores . get ( matchId ) ?. get ( ) ;
123+ }
124+ function getMatchList ( matchId ) {
125+ const pendingMatches = router . stores . pendingMatches . get ( ) ;
126+ if ( pendingMatches . some ( match => match . id === matchId ) ) {
127+ return pendingMatches ;
128+ }
129+ ;
130+ const activeMatches = router . stores . matches . get ( ) ;
131+ if ( activeMatches . some ( match => match . id === matchId ) ) {
132+ return activeMatches ;
133+ }
134+ ;
135+ const cachedMatches = router . stores . cachedMatches . get ( ) ;
136+ if ( cachedMatches . some ( match => match . id === matchId ) ) {
137+ return cachedMatches ;
138+ }
139+ ;
140+ return [ ] ;
141+ }
142+ function getParentMatch ( match ) {
143+ const matchList = getMatchList ( match . id ) ;
144+ const matchIndex = matchList . findIndex ( item => item . id === match . id ) ;
145+ if ( matchIndex <= 0 ) {
146+ return undefined ;
147+ }
148+ ;
149+ const parentMatch = matchList [ matchIndex - 1 ] ;
150+ return getStoreMatch ( parentMatch . id ) || parentMatch ;
151+ }
152+ function rebuildMatchContextWithoutBeforeLoad ( match ) {
153+ const parentMatch = getParentMatch ( match ) ;
154+ const getParentContext = router . getParentContext ;
155+ const parentContext = getParentContext ? getParentContext . call ( router , parentMatch ) : parentMatch ?. context ?? router . options . context ;
156+ return {
157+ ...( parentContext ?? { } ) ,
158+ ...( match . __routeContext ?? { } )
159+ } ;
160+ }
161+ } ) ( routeId , newModule . Route ) ;
162+ }
163+ } ) ;
164+ }
0 commit comments