pull/4525/head
Divyansh Singh 7 months ago
parent 18994427a6
commit d3ec222553

@ -33,6 +33,10 @@ export type ResolvedRouteConfig = UserRouteConfig & {
* absolute fs path * absolute fs path
*/ */
fullPath: string fullPath: string
/**
* the path to the paths loader module
*/
loaderPath: string
} }
export interface RouteModule { export interface RouteModule {
@ -128,7 +132,9 @@ export const dynamicRoutesPlugin = async (
if (matched) { if (matched) {
const { route, params, content } = matched const { route, params, content } = matched
const routeFile = normalizePath(path.resolve(config.srcDir, route)) const routeFile = normalizePath(path.resolve(config.srcDir, route))
moduleGraph.add(id, [routeFile]) moduleGraph.add(id, [routeFile])
moduleGraph.add(routeFile, [matched.loaderPath])
let baseContent = fs.readFileSync(routeFile, 'utf-8') let baseContent = fs.readFileSync(routeFile, 'utf-8')
@ -222,7 +228,9 @@ async function resolveDynamicRoutes(
let watch: ResolvedRouteModule['watch'] let watch: ResolvedRouteModule['watch']
let loader: ResolvedRouteModule['loader'] let loader: ResolvedRouteModule['loader']
const existing = routeModuleCache.get(normalizePath(pathsFile)) const loaderPath = normalizePath(pathsFile)
const existing = routeModuleCache.get(loaderPath)
if (existing) { if (existing) {
// use cached routes if not invalidated by hmr // use cached routes if not invalidated by hmr
if (existing.routes) { if (existing.routes) {
@ -284,10 +292,9 @@ async function resolveDynamicRoutes(
// record deps for hmr // record deps for hmr
newModuleGraph.add( newModuleGraph.add(
normalizePath(pathsFile), loaderPath,
mod.dependencies.map((f) => normalizePath(path.resolve(f))) mod.dependencies.map((p) => normalizePath(path.resolve(p)))
) )
newModuleGraph.add(fullPath, [normalizePath(pathsFile)])
} }
const resolveRoute = async (): Promise<ResolvedRouteConfig[]> => { const resolveRoute = async (): Promise<ResolvedRouteConfig[]> => {
@ -317,11 +324,12 @@ async function resolveDynamicRoutes(
path: resolvedPath, path: resolvedPath,
fullPath: normalizePath(path.resolve(srcDir, resolvedPath)), fullPath: normalizePath(path.resolve(srcDir, resolvedPath)),
route, route,
loaderPath,
...userConfig ...userConfig
} }
}) })
routeModuleCache.set(normalizePath(pathsFile), { watch, routes, loader }) routeModuleCache.set(loaderPath, { watch, routes, loader })
return routes return routes
} }

@ -27,7 +27,7 @@ export class ModuleGraph {
// Merge the new dependencies with any that already exist. // Merge the new dependencies with any that already exist.
for (const dep of dependencies) { for (const dep of dependencies) {
if (!moduleNode.dependencies.has(dep)) { if (!moduleNode.dependencies.has(dep) && dep !== module) {
moduleNode.dependencies.add(dep) moduleNode.dependencies.add(dep)
// Ensure the dependency exists in the graph. // Ensure the dependency exists in the graph.
if (!this.nodes.has(dep)) { if (!this.nodes.has(dep)) {

Loading…
Cancel
Save