Repository: withastro/astro
File: packages/astro/src/vite-plugin-astro-server/plugin.ts (TypeScript)

Code before:
					const routePath = fileURLToPath(new URL(route.component, settings.config.root));
					if (!fsMod.existsSync(routePath)) {
						// Route was renamed so it does not exist anymore
						return;
					}
					const content = await fsMod.promises.readFile(routePath, 'utf-8');
					await getRoutePrerenderOption(content, route, settings, logger);
				} else {
					routeManifest = injectDefaultDevRoutes(
						settings,
						devSSRManifest,
						await createRouteManifest({ settings, fsMod }, logger, { dev: true }),
					);
				}
				await runHookRoutesResolved({ routes: routeManifest.routes, settings, logger });

				warnMissingAdapter(logger, settings);
				pipeline.manifest.checkOrigin =
					settings.config.security.checkOrigin && settings.buildOutput === 'server';
				pipeline.setManifestData(routeManifest);
			}

			// Rebuild route manifest on file change
			viteServer.watcher.on('add', () => rebuildManifest());
			viteServer.watcher.on('unlink', () => rebuildManifest());
			viteServer.watcher.on('change', (path) => rebuildManifest(path));

			function handleUnhandledRejection(rejection: any) {
				const error = new AstroError({
					...AstroErrorData.UnhandledRejection,
					message: AstroErrorData.UnhandledRejection.message(rejection?.stack || rejection),
				});
				const store = localStorage.getStore();
				if (store instanceof IncomingMessage) {
					const request = store;
					setRouteError(controller.state, request.url!, error);
				}
				const { errorWithMetadata } = recordServerError(loader, settings.config, pipeline, error);
				setTimeout(
					async () => loader.webSocketSend(await getViteErrorPayload(errorWithMetadata)),
					200,
				);
			}

			process.on('unhandledRejection', handleUnhandledRejection);
			viteServer.httpServer?.on('close', () => {
				process.off('unhandledRejection', handleUnhandledRejection);
			});

			return () => {
				// Push this middleware to the front of the stack so that it can intercept responses.

Review comment (suggestion):
```suggestion
			viteServer.watcher.on('add', rebuildManifest);
			viteServer.watcher.on('unlink', rebuildManifest);
			viteServer.watcher.on('change', rebuildManifest);
```

I think this should work

Code after:
					}
					if (route.type !== 'page' && route.type !== 'endpoint') return;

					const routePath = fileURLToPath(new URL(route.component, settings.config.root));
					try {
						const content = await fsMod.promises.readFile(routePath, 'utf-8');
						await getRoutePrerenderOption(content, route, settings, logger);
					} catch (_) {}
				} else {
					routeManifest = injectDefaultDevRoutes(
						settings,
						devSSRManifest,
						await createRouteManifest({ settings, fsMod }, logger, { dev: true }),
					);
				}
				await runHookRoutesResolved({ routes: routeManifest.routes, settings, logger });

				warnMissingAdapter(logger, settings);
				pipeline.manifest.checkOrigin =
					settings.config.security.checkOrigin && settings.buildOutput === 'server';
				pipeline.setManifestData(routeManifest);
			}

			// Rebuild route manifest on file change
			viteServer.watcher.on('add', rebuildManifest.bind(null, null));
			viteServer.watcher.on('unlink', rebuildManifest.bind(null, null));
			viteServer.watcher.on('change', rebuildManifest);

			function handleUnhandledRejection(rejection: any) {
				const error = new AstroError({
					...AstroErrorData.UnhandledRejection,
					message: AstroErrorData.UnhandledRejection.message(rejection?.stack || rejection),
				});
				const store = localStorage.getStore();
				if (store instanceof IncomingMessage) {
					const request = store;
					setRouteError(controller.state, request.url!, error);
				}
				const { errorWithMetadata } = recordServerError(loader, settings.config, pipeline, error);
				setTimeout(
					async () => loader.webSocketSend(await getViteErrorPayload(errorWithMetadata)),
					200,
				);
			}

			process.on('unhandledRejection', handleUnhandledRejection);
			viteServer.httpServer?.on('close', () => {
				process.off('unhandledRejection', handleUnhandledRejection);
			});

			return () => {