Skip to content

Commit

Permalink
fix: change strategy for route caching (#10248)
Browse files Browse the repository at this point in the history
* fix: change strategy for route caching

* use route and component as cache key
  • Loading branch information
ematipico authored Feb 28, 2024
1 parent 9b00de0 commit 8ae5d99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-flowers-own.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 9 additions & 4 deletions packages/astro/src/core/render/route-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
}

Expand Down

0 comments on commit 8ae5d99

Please sign in to comment.