diff --git a/.changeset/great-flowers-own.md b/.changeset/great-flowers-own.md new file mode 100644 index 000000000000..a2295691f2d2 --- /dev/null +++ b/.changeset/great-flowers-own.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes an issue where multiple injected routes with the same `entrypoint` but different `pattern` were incorrectly cached, causing some of them not being rendered in the dev server. diff --git a/packages/astro/src/core/render/route-cache.ts b/packages/astro/src/core/render/route-cache.ts index 8a4e821a523c..b6542222be8f 100644 --- a/packages/astro/src/core/render/route-cache.ts +++ b/packages/astro/src/core/render/route-cache.ts @@ -99,17 +99,22 @@ export class RouteCache { } set(route: RouteData, entry: RouteCacheEntry): void { + const key = this.key(route); // NOTE: This shouldn't be called on an already-cached component. // Warn here so that an unexpected double-call of getStaticPaths() // isn't invisible and developer can track down the issue. - if (this.mode === 'production' && this.cache[route.component]?.staticPaths) { - this.logger.warn(null, `Internal Warning: route cache overwritten. (${route.component})`); + if (this.mode === 'production' && this.cache[key]?.staticPaths) { + this.logger.warn(null, `Internal Warning: route cache overwritten. (${key})`); } - this.cache[route.component] = entry; + this.cache[key] = entry; } get(route: RouteData): RouteCacheEntry | undefined { - return this.cache[route.component]; + return this.cache[this.key(route)]; + } + + key(route: RouteData) { + return `${route.route}_${route.component}`; } }