@@ -170,6 +170,7 @@ export function createRoutesContext(options: ResolvedOptions) {
170
170
// unlinkDir event
171
171
}
172
172
173
+ let lastAutoRoutes : string | undefined
173
174
function generateRoutes ( ) {
174
175
const importsMap = new ImportsMap ( )
175
176
@@ -181,14 +182,22 @@ export function createRoutesContext(options: ResolvedOptions) {
181
182
// TODO: should we put some HMR code for routes here or should it be at the router creation level (that would be easier to replace the routes)
182
183
183
184
// generate the list of imports
184
- let imports = ` ${ importsMap } `
185
+ let imports = importsMap . toString ( )
185
186
// add an empty line for readability
186
187
if ( imports ) {
187
188
imports += '\n'
188
189
}
189
190
191
+ const newAutoRoutes = `${ imports } ${ routesExport } \n`
192
+
193
+ if ( lastAutoRoutes !== newAutoRoutes ) {
194
+ // cache hit, triigger HMR (not working yet)
195
+ server ?. updateRoutes ( )
196
+ lastAutoRoutes = newAutoRoutes
197
+ }
198
+
190
199
// prepend it to the code
191
- return ` ${ imports } ${ routesExport } \n`
200
+ return newAutoRoutes
192
201
}
193
202
194
203
function generateDTS ( ) : string {
@@ -224,12 +233,6 @@ export function createRoutesContext(options: ResolvedOptions) {
224
233
await fs . writeFile ( dts , content , 'utf-8' )
225
234
logger . timeLog ( 'writeConfigFiles' , 'wrote dts file' )
226
235
lastDTS = content
227
-
228
- // update the files
229
- server && logger . log ( `⚙️ Invalidating server "${ MODULE_ROUTES_PATH } "` )
230
- // server?.invalidate(MODULE_ROUTES_PATH)
231
- server ?. updateRoutes ( )
232
- // server?.reload()
233
236
}
234
237
}
235
238
logger . timeEnd ( 'writeConfigFiles' )
0 commit comments