* closes #4633

* chore: add changeset
This commit is contained in:
Tony Sullivan 2022-10-04 16:16:47 +00:00 committed by GitHub
parent 67099805f4
commit 4f73b98ae0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes a bug that logged route cache warnings in `astro dev`

View file

@ -5,6 +5,7 @@ import type {
GetStaticPathsResultKeyed, GetStaticPathsResultKeyed,
Params, Params,
RouteData, RouteData,
RuntimeMode,
} from '../../@types/astro'; } from '../../@types/astro';
import { debug, LogOptions, warn } from '../logger/core.js'; import { debug, LogOptions, warn } from '../logger/core.js';
@ -77,9 +78,11 @@ export interface RouteCacheEntry {
export class RouteCache { export class RouteCache {
private logging: LogOptions; private logging: LogOptions;
private cache: Record<string, RouteCacheEntry> = {}; private cache: Record<string, RouteCacheEntry> = {};
private mode: RuntimeMode;
constructor(logging: LogOptions) { constructor(logging: LogOptions, mode: RuntimeMode = 'production') {
this.logging = logging; this.logging = logging;
this.mode = mode;
} }
/** Clear the cache. */ /** Clear the cache. */
@ -91,7 +94,7 @@ export class RouteCache {
// NOTE: This shouldn't be called on an already-cached component. // NOTE: This shouldn't be called on an already-cached component.
// Warn here so that an unexpected double-call of getStaticPaths() // Warn here so that an unexpected double-call of getStaticPaths()
// isn't invisible and developer can track down the issue. // isn't invisible and developer can track down the issue.
if (this.cache[route.component]) { if (this.mode === 'production' && this.cache[route.component]) {
warn( warn(
this.logging, this.logging,
'routeCache', 'routeCache',

View file

@ -436,7 +436,7 @@ export default function createPlugin({ settings, logging }: AstroPluginOptions):
return { return {
name: 'astro:server', name: 'astro:server',
configureServer(viteServer) { configureServer(viteServer) {
let routeCache = new RouteCache(logging); let routeCache = new RouteCache(logging, 'development');
let manifest: ManifestData = createRouteManifest({ settings }, logging); let manifest: ManifestData = createRouteManifest({ settings }, logging);
/** rebuild the route cache + manifest, as needed. */ /** rebuild the route cache + manifest, as needed. */
function rebuildManifest(needsManifestRebuild: boolean, file: string) { function rebuildManifest(needsManifestRebuild: boolean, file: string) {