Skip to content

Commit

Permalink
use route and component as cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Feb 28, 2024
1 parent 83a4a0f commit c3f1678
Showing 1 changed file with 9 additions and 4 deletions.
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.route]?.staticPaths) {
this.logger.warn(null, `Internal Warning: route cache overwritten. (${route.route})`);
if (this.mode === 'production' && this.cache[key]?.staticPaths) {
this.logger.warn(null, `Internal Warning: route cache overwritten. (${key})`);
}
this.cache[route.route] = entry;
this.cache[key] = entry;
}

get(route: RouteData): RouteCacheEntry | undefined {
return this.cache[route.route];
return this.cache[this.key(route)];
}

key(route: RouteData) {
return `${route.route}_${route.component}`;
}
}

Expand Down

0 comments on commit c3f1678

Please sign in to comment.