From d5094f86d69408c6ac3c26412029105c061378d6 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Sun, 10 Aug 2025 02:49:25 +0530 Subject: [PATCH] wip --- __tests__/e2e/dynamic-routes/[id].md | 8 ++++++++ src/node/plugins/dynamicRoutesPlugin.ts | 26 +++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/__tests__/e2e/dynamic-routes/[id].md b/__tests__/e2e/dynamic-routes/[id].md index ec1b0762..6cb8de80 100644 --- a/__tests__/e2e/dynamic-routes/[id].md +++ b/__tests__/e2e/dynamic-routes/[id].md @@ -1,3 +1,11 @@
{{ $params }}
+ + diff --git a/src/node/plugins/dynamicRoutesPlugin.ts b/src/node/plugins/dynamicRoutesPlugin.ts index f10aa27f..41700d01 100644 --- a/src/node/plugins/dynamicRoutesPlugin.ts +++ b/src/node/plugins/dynamicRoutesPlugin.ts @@ -5,6 +5,7 @@ import pm from 'picomatch' import { loadConfigFromFile, normalizePath, + type EnvironmentModuleGraph, type EnvironmentModuleNode, type Logger, type Plugin @@ -177,11 +178,7 @@ export const dynamicRoutesPlugin = async ( const normalizedFile = normalizePath(file) // Trigger update if a module or its dependencies changed. - for (const id of moduleGraph.delete(normalizedFile)) { - routeModuleCache.delete(id) - const mod = this.environment.moduleGraph.getModuleById(id) - if (mod) modules.push(mod) - } + modules.push(...getModules(normalizedFile, this.environment.moduleGraph)) // Also check if the file matches any custom watch patterns. let watchedFileChanged = false @@ -192,11 +189,7 @@ export const dynamicRoutesPlugin = async ( ) { route.routes = undefined watchedFileChanged = true - - for (const id of moduleGraph.delete(file)) { - const mod = this.environment.moduleGraph.getModuleById(id) - if (mod) modules.push(mod) - } + modules.push(...getModules(file, this.environment.moduleGraph, false)) } } @@ -355,3 +348,16 @@ async function resolveDynamicRoutes( return resolvedRoutes } + +function getModules( + id: string, + envModuleGraph: EnvironmentModuleGraph, + deleteFromRouteModuleCache = true +) { + const modules: EnvironmentModuleNode[] = [] + for (const file of moduleGraph.delete(id)) { + deleteFromRouteModuleCache && routeModuleCache.delete(file) + modules.push(...(envModuleGraph.getModulesByFile(file)?.values() ?? [])) + } + return modules +}