Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-initial-route-scan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": patch
---

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.
17 changes: 15 additions & 2 deletions packages/start/src/config/fs-routes/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ export class BaseFileSystemRouter extends EventTarget {
}

async buildRoutes(): Promise<any[]> {
for (var src of glob(this.glob())) {
await this.addRoute(src);
this.initialScan = true;
try {
for (var src of glob(this.glob())) {
await this.addRoute(src);
}
} finally {
this.initialScan = false;
}

return this.routes;
Expand Down Expand Up @@ -119,7 +124,15 @@ export class BaseFileSystemRouter extends EventTarget {
}
}

// "reload" listeners invalidate the routes manifest module, so the events
// must stay quiet while buildRoutes first discovers the existing files:
// a manifest already served to the browser would otherwise be invalidated
// ~200ms into the first request, racing hydration with an HMR update of
// the app/router module chain.
private initialScan = false;

reload(route: string, type: "update" | "remove" | "add") {
if (this.initialScan) return;
this.dispatchEvent(
new CustomEvent("reload", {
detail: {
Expand Down
Loading