diff --git a/.changeset/ninety-monkeys-complain.md b/.changeset/ninety-monkeys-complain.md new file mode 100644 index 000000000000..c8a06da1f37f --- /dev/null +++ b/.changeset/ninety-monkeys-complain.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Clear content layer cache when astro version changes diff --git a/packages/astro/src/content/content-layer.ts b/packages/astro/src/content/content-layer.ts index c07d5dd55f8a..b2729ce4dd72 100644 --- a/packages/astro/src/content/content-layer.ts +++ b/packages/astro/src/content/content-layer.ts @@ -151,13 +151,27 @@ export class ContentLayer { const { digest: currentConfigDigest } = contentConfig.config; this.#lastConfigDigest = currentConfigDigest; + let shouldClear = false; const previousConfigDigest = await this.#store.metaStore().get('config-digest'); + const previousAstroVersion = await this.#store.metaStore().get('astro-version'); if (currentConfigDigest && previousConfigDigest !== currentConfigDigest) { - logger.info('Content config changed, clearing cache'); + logger.info('Content config changed'); + shouldClear = true; + } + if (process.env.ASTRO_VERSION && previousAstroVersion !== process.env.ASTRO_VERSION) { + logger.info('Astro version changed'); + shouldClear = true; + } + if (shouldClear) { + logger.info('Clearing content store'); this.#store.clearAll(); + } + if (process.env.ASTRO_VERSION) { + await this.#store.metaStore().set('astro-version', process.env.ASTRO_VERSION); + } + if (currentConfigDigest) { await this.#store.metaStore().set('config-digest', currentConfigDigest); } - await Promise.all( Object.entries(contentConfig.config.collections).map(async ([name, collection]) => { if (collection.type !== CONTENT_LAYER_TYPE) {