You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#14 made the initial scan sort route files, but the watcher path still changes the order. _addRoute removes an existing entry and pushes the new one to the end, and new files are always appended. The Vite plugin calls updateRoute on every change event (src/vite/fs-watcher.ts) and, with types enabled, regenerates the declaration, which is rewritten because its order changed. Saving a route file during development reorders the generated .d.ts and the virtual manifest even when nothing about the routes changed. In a project that commits the declaration, editing a route file that isn't already last in the manifest shows up as a diff, and a later build puts the order back.
Reproduction
Verified with filesystem-routing@0.4.0 from npm on Node 24.22.1. Save as repro.mjs in a project that depends on filesystem-routing@0.4.0 and run node repro.mjs:
import{mkdtempSync,writeFileSync}from'node:fs'import{tmpdir}from'node:os'import{join}from'node:path'import{PageFileSystemRouter}from'filesystem-routing'constdir=mkdtempSync(join(tmpdir(),'routes-'))for(constnameof['about','contact','zebra']){writeFileSync(join(dir,`${name}.tsx`),'export default () => null;')}constrouter=newPageFileSystemRouter({ dir,extensions: ['tsx']})constpaths=()=>router.routes.map(route=>route.path).join(' ')awaitrouter.getRoutes()console.log('scan: ',paths())// What the Vite watcher does when about.tsx is saved.awaitrouter.updateRoute(join(dir,'about.tsx'))console.log('after update: ',paths())writeFileSync(join(dir,'blog.tsx'),'export default () => null;')awaitrouter.addRoute(join(dir,'blog.tsx'))console.log('after add: ',paths())constfresh=newPageFileSystemRouter({ dir,extensions: ['tsx']})console.log('fresh scan: ',(awaitfresh.getRoutes()).map(route=>route.path).join(' '))
After any sequence of watcher events, router.routes has the same order as a fresh scan of the same files: an updated route keeps its position, and a new route is inserted where the sorted scan would put it.
Activity