Skip to content
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/fix-content-collection-stale-entry-on-delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes deleted content collection entries persisting in `getCollection()` results during dev
15 changes: 14 additions & 1 deletion packages/astro/src/content/vite-plugin-content-virtual-mod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import nodeFs from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dataToEsm } from '@rollup/pluginutils';
import { normalizePath, type Plugin, type ViteDevServer } from 'vite';
import { isRunnableDevEnvironment, normalizePath, type Plugin, type ViteDevServer } from 'vite';
import { ASTRO_VITE_ENVIRONMENT_NAMES } from '../core/constants.js';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import { rootRelativePath } from '../core/viteUtils.js';
Expand Down Expand Up @@ -39,6 +39,19 @@ function invalidateDataStore(viteServer: ViteDevServer) {
// Pass `true` to mark this as HMR invalidation so Vite drops cached SSR results.
environment.moduleGraph.invalidateModule(module, undefined, timestamp, true);
}
// Also invalidate the module in the SSR module runner's evaluation cache.
// Server-side invalidation only clears `transformResult`, but the runner
// may still hold a stale evaluated result. When the runner's `fetchModule`
// call triggers a fresh server transform, the transform re-populates
// `transformResult` before the runner checks it, causing a false cache hit.
if (isRunnableDevEnvironment(environment)) {
const runnerModule = environment.runner.evaluatedModules.getModuleById(
RESOLVED_DATA_STORE_VIRTUAL_ID,
);
if (runnerModule) {
environment.runner.evaluatedModules.invalidateModule(runnerModule);
}
}
// Signal the SSR runner to clear its route cache so that getStaticPaths()
// is re-evaluated with the updated content collection data.
environment.hot.send('astro:content-changed', {});
Expand Down
Loading