Skip to content
Open
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/full-ties-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixed an issue where the API fetch in the frontmatter was not triggered when modifying external CMS content while the development server was running.
3 changes: 3 additions & 0 deletions packages/astro/src/vite-plugin-app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ export class AstroServerApp extends BaseApp<RunnablePipeline> {

const self = this;
await self.#loadFetchHandler();
// Clear the route cache on every dev request so that getStaticPaths()
// re-runs when external data (e.g. a headless CMS) changes between requests.
self.pipeline.clearRouteCache();

let handled = true;
await runWithErrorHandling({
Expand Down
40 changes: 40 additions & 0 deletions packages/astro/test/dev-route-cache.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { type DevServer, type Fixture, loadFixture } from './test-utils.ts';

// getStaticPaths() results were cached indefinitely during `astro dev`,
// so external data changes (e.g. headless CMS) were never reflected without restarting the dev server.
describe('dev: route cache is cleared between requests', () => {
let fixture: Fixture;
let devServer: DevServer;

before(async () => {
fixture = await loadFixture({ root: './fixtures/hmr-route-cache/' });
devServer = await fixture.startDevServer();
});

after(async () => {
await devServer?.stop();
});

it('re-runs getStaticPaths() on each request', async () => {
const res1 = await fixture.fetch('/test');
assert.equal(res1.status, 200);
const time1 = Number.parseInt(
cheerio
.load(await res1.text())('#time')
.text(),
);
await new Promise((r) => setTimeout(r, 10));
const res2 = await fixture.fetch('/test');
assert.equal(res2.status, 200);
const time2 = Number.parseInt(
cheerio
.load(await res2.text())('#time')
.text(),
);

assert.notEqual(time1, time2);
});
});
8 changes: 8 additions & 0 deletions packages/astro/test/fixtures/hmr-route-cache/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/hmr-route-cache",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
export async function getStaticPaths() {
return [{ params: { id: 'test' }, props: { callTime: Date.now() } }];
}
const { callTime } = Astro.props;
---
<p id="time">{callTime}</p>
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading