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

Code before:
			const loader = createViteLoader(viteServer);
			const pipeline = DevPipeline.create(routeManifest, {
				loader,
				logger,
				manifest: devSSRManifest,
				settings,
			});
			const controller = createController({ loader });
			const localStorage = new AsyncLocalStorage();

			/** rebuild the route cache + manifest */
			async function rebuildManifest(path: string | null = null) {
				pipeline.clearRouteCache();

				// If a route changes, we check if it's part of the manifest and check for its prerender value
				if (path !== null) {
					const route = routeManifest.routes.find((r) => path.endsWith(r.component));
					if (!route) {
						return;
					}
					if (route.type !== 'page' && route.type !== 'endpoint') return;

					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.bind(null));
			viteServer.watcher.on('unlink', rebuildManifest.bind(null));
			viteServer.watcher.on('change', rebuildManifest);

			function handleUnhandledRejection(rejection: any) {
				const error = new AstroError({

Review comment (suggestion):
`route.component` can also be an import path (like `@astrojs/starlight/index.astro`). In that case the `new URL` won't resolve to the file path so it will reach this conditional.

I don't think this is a problem since this would only be reached on a conflict from my other comment. But maybe it should be in the comment.

Code after:
		configureServer(viteServer) {
			const loader = createViteLoader(viteServer);
			const pipeline = DevPipeline.create(routeManifest, {
				loader,
				logger,
				manifest: devSSRManifest,
				settings,
			});
			const controller = createController({ loader });
			const localStorage = new AsyncLocalStorage();

			/** rebuild the route cache + manifest */
			async function rebuildManifest(path: string | null = null) {
				pipeline.clearRouteCache();

				// If a route changes, we check if it's part of the manifest and check for its prerender value
				if (path !== null) {
					const route = routeManifest.routes.find(
						(r) =>
							normalizePath(path) ===
							normalizePath(fileURLToPath(new URL(r.component, settings.config.root))),
					);
					if (!route) {
						return;
					}
					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);