Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #4633 #4977

Merged
merged 2 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lemon-pets-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a bug that logged route cache warnings in `astro dev`
7 changes: 5 additions & 2 deletions packages/astro/src/core/render/route-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
GetStaticPathsResultKeyed,
Params,
RouteData,
RuntimeMode,
} from '../../@types/astro';
import { debug, LogOptions, warn } from '../logger/core.js';

Expand Down Expand Up @@ -77,9 +78,11 @@ export interface RouteCacheEntry {
export class RouteCache {
private logging: LogOptions;
private cache: Record<string, RouteCacheEntry> = {};
private mode: RuntimeMode;

constructor(logging: LogOptions) {
constructor(logging: LogOptions, mode: RuntimeMode = 'production') {
this.logging = logging;
this.mode = mode;
}

/** Clear the cache. */
Expand All @@ -91,7 +94,7 @@ export class RouteCache {
// 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.cache[route.component]) {
if (this.mode === 'production' && this.cache[route.component]) {
warn(
this.logging,
'routeCache',
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-astro-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export default function createPlugin({ settings, logging }: AstroPluginOptions):
return {
name: 'astro:server',
configureServer(viteServer) {
let routeCache = new RouteCache(logging);
let routeCache = new RouteCache(logging, 'development');
let manifest: ManifestData = createRouteManifest({ settings }, logging);
/** rebuild the route cache + manifest, as needed. */
function rebuildManifest(needsManifestRebuild: boolean, file: string) {
Expand Down