[PR #235] [MERGED] fix: new routes fail on running dev server #408

Closed
opened 2026-05-06 12:39:40 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/235
Author: @southpolesteve
Created: 3/3/2026
Status: Merged
Merged: 3/3/2026
Merged by: @southpolesteve

Base: mainHead: fix/hot-route-reload-226


📝 Commits (2)

  • d951af6 Skip deploy previews for fork PRs that lack Cloudflare secrets
  • c63b575 fix: invalidate virtual RSC entry when app routes are added or removed

📊 Changes

2 files changed (+25 additions, -3 deletions)

View changed files

📝 .github/workflows/deploy-examples.yml (+3 -3)
📝 packages/vinext/src/index.ts (+22 -0)

📄 Description

Summary

  • Fixes #226: New App Router routes created while vinext dev is running now work without a server restart

Problem

The App Router route table is baked into the virtual RSC entry module (virtual:vinext-rsc-entry) at generation time. When a new route file is added while the dev server is running:

  1. The file watcher correctly calls invalidateAppRouteCache() to clear the route scanner cache
  2. But the virtual module in Vite's module graph was never invalidated
  3. So Vite never re-called the load() hook to regenerate the entry with the updated route table
  4. Result: 404 for new routes until server restart

The Pages Router was unaffected because it re-scans routes on every request via pagesRouter(pagesDir).

Fix

After clearing the route cache, also invalidate the virtual RSC entry module in Vite's module graph and send a full-reload to the RSC environment. This forces the load() hook to re-run, regenerating the route table with the new route.

The same fix applies to both file addition (add) and file removal (unlink) handlers.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/235 **Author:** [@southpolesteve](https://github.com/southpolesteve) **Created:** 3/3/2026 **Status:** ✅ Merged **Merged:** 3/3/2026 **Merged by:** [@southpolesteve](https://github.com/southpolesteve) **Base:** `main` ← **Head:** `fix/hot-route-reload-226` --- ### 📝 Commits (2) - [`d951af6`](https://github.com/cloudflare/vinext/commit/d951af6a9bc4e890d8a74fc668b4d588ba923257) Skip deploy previews for fork PRs that lack Cloudflare secrets - [`c63b575`](https://github.com/cloudflare/vinext/commit/c63b575c248c2d5a82bcf03d7a959260b6b6bbc0) fix: invalidate virtual RSC entry when app routes are added or removed ### 📊 Changes **2 files changed** (+25 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/deploy-examples.yml` (+3 -3) 📝 `packages/vinext/src/index.ts` (+22 -0) </details> ### 📄 Description ## Summary - Fixes #226: New App Router routes created while `vinext dev` is running now work without a server restart ## Problem The App Router route table is baked into the virtual RSC entry module (`virtual:vinext-rsc-entry`) at generation time. When a new route file is added while the dev server is running: 1. The file watcher correctly calls `invalidateAppRouteCache()` to clear the route scanner cache 2. But the virtual module in Vite's module graph was never invalidated 3. So Vite never re-called the `load()` hook to regenerate the entry with the updated route table 4. Result: 404 for new routes until server restart The Pages Router was unaffected because it re-scans routes on every request via `pagesRouter(pagesDir)`. ## Fix After clearing the route cache, also invalidate the virtual RSC entry module in Vite's module graph and send a full-reload to the RSC environment. This forces the `load()` hook to re-run, regenerating the route table with the new route. The same fix applies to both file addition (`add`) and file removal (`unlink`) handlers. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:39:40 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#408
No description provided.