Skip to content
Merged
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/sweet-socks-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes an issue where HMR didn't correctly work on Windows when adding/changing/deleting routes in `pages/`.
7 changes: 5 additions & 2 deletions packages/astro/src/manifest/serialized.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Plugin, ViteDevServer } from 'vite';
import { fileURLToPath } from 'node:url';
import { normalizePath, type Plugin, type ViteDevServer } from 'vite';
import { ACTIONS_ENTRYPOINT_VIRTUAL_MODULE_ID } from '../actions/consts.js';
import { toFallbackType } from '../core/app/common.js';
import { toRoutingStrategy } from '../core/app/entrypoints/index.js';
Expand Down Expand Up @@ -41,8 +42,10 @@ export function serializedManifestPlugin({
command: 'dev' | 'build';
sync: boolean;
}): Plugin {
const normalizedSrcDir = normalizePath(fileURLToPath(settings.config.srcDir));

function reloadManifest(path: string | null, server: ViteDevServer) {
if (path != null && path.startsWith(settings.config.srcDir.pathname)) {
if (path != null && normalizePath(path).startsWith(normalizedSrcDir)) {
const environment = server.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr];
const virtualMod = environment.moduleGraph.getModuleById(SERIALIZED_MANIFEST_RESOLVED_ID);
if (!virtualMod) return;
Expand Down
6 changes: 4 additions & 2 deletions packages/astro/src/vite-plugin-routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ export default async function astroPluginRoutes({
},
);

const normalizedSrcDir = normalizePath(fileURLToPath(settings.config.srcDir));

async function rebuildRoutes(path: string | null = null, server: ViteDevServer) {
if (path != null && path.startsWith(settings.config.srcDir.pathname)) {
if (path != null && normalizePath(path).startsWith(normalizedSrcDir)) {
logger.debug(
'update',
`Re-calculating routes for ${path.slice(settings.config.srcDir.pathname.length)}`,
`Re-calculating routes for ${normalizePath(path).slice(normalizedSrcDir.length)}`,
);
const file = pathToFileURL(normalizePath(path));
const newRoutesList = await createRoutesList(
Expand Down
Loading