Skip to content

Commit 98c0fd4

Browse files
brenelzclaude
andcommitted
fix: suppress route reload events during the initial route scan
The first dev request triggers buildRoutes(), which emitted a "reload" event per discovered file. The fs-watcher's debounced handlers then invalidated the routes manifest ~200ms after it had already been served, pushing an HMR update that re-imported solid-start:routes, router.jsx, and the user's app.tsx as fresh module instances while hydration was still in flight. Depending on where the update landed, dev sessions saw duplicated pages, dead client-side navigation, or actions whose handlers lived in the stale module instance. Cold-start reproduction fired on roughly half of runs; with the scan quiet it no longer fires at all, while edits and added/removed route files still reload as before. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 22f07b8 commit 98c0fd4

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/start": patch
3+
---
4+
5+
Don't emit route "reload" events during the initial file-system route scan. The scan runs on the first dev request, and the events invalidated the just-served routes manifest ~200ms later, pushing a spurious HMR update of the app/router module chain that raced hydration — intermittently duplicating pages, breaking client-side navigation, and detaching actions in dev.

‎packages/start/src/config/fs-routes/router.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ export class BaseFileSystemRouter extends EventTarget {
5555
}
5656

5757
async buildRoutes(): Promise<any[]> {
58-
for (var src of glob(this.glob())) {
59-
await this.addRoute(src);
58+
this.initialScan = true;
59+
try {
60+
for (var src of glob(this.glob())) {
61+
await this.addRoute(src);
62+
}
63+
} finally {
64+
this.initialScan = false;
6065
}
6166

6267
return this.routes;
@@ -119,7 +124,15 @@ export class BaseFileSystemRouter extends EventTarget {
119124
}
120125
}
121126

127+
// "reload" listeners invalidate the routes manifest module, so the events
128+
// must stay quiet while buildRoutes first discovers the existing files:
129+
// a manifest already served to the browser would otherwise be invalidated
130+
// ~200ms into the first request, racing hydration with an HMR update of
131+
// the app/router module chain.
132+
private initialScan = false;
133+
122134
reload(route: string, type: "update" | "remove" | "add") {
135+
if (this.initialScan) return;
123136
this.dispatchEvent(
124137
new CustomEvent("reload", {
125138
detail: {

0 commit comments

Comments
 (0)