You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Content collection changes ignored after dev server restarts on config change #18216
- P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)triage: fix verifiedReporter confirmed the triage bot fix works
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
After the dev server restarts because of a config change ("Configuration file updated. Restarting..."), content collection changes are no longer picked up. Edits to entries are silently ignored until astro dev is restarted manually.
This is a regression of #12976 (fixed in #12984). It came back with #16059, which switched config restarts to an in-place viteServer.restart(). Vite closes the old file watcher and creates a new one, but the content layer is never re-initialized, so loaders keep listening on the closed watcher. The content layer also keeps the settings from before the restart.
Steps, using the unmodified blog template:
npm create astro@latest -- --template blog, then astro dev
Edit the title in src/content/blog/first-post.md: /blog updates, the log shows [glob-loader] Reloaded data from first-post.md
touch astro.config.mjs: the log shows Configuration file updated. Restarting...
Edit the title again: nothing in the log, /blog still shows the old title, also after a page reload
Restarts are not only caused by config edits: on the first astro dev run, writing .astro/settings.json triggers one right after startup, so content updates don't work from the start.
What's the expected result?
Content changes are picked up after a dev server restart, as before #16059.
Unit Test: Yes, as an integration test: packages/astro/test/content-layer-dev-restart.test.ts
Priority:P4: important. This is a regression in a core dev workflow. Content collection edits stop showing up in astro dev after any config restart, and nothing in the log says so. The only workaround is to restart astro dev by hand.
Since #16059, a config change restarts the dev server in place with viteServer.restart() (packages/astro/src/core/dev/restart.ts). This closes Vite's old file watcher and puts a new one on the same server object. The global ContentLayer, created once in core/dev/dev.ts, is never re-initialized. Its loaders (glob/file) stay subscribed to the closed watcher, and it keeps the settings from before the restart. The old restart path (the #12984 fix for #12976) re-initialized the content layer through createContainer({ isRestart: true }) → syncInternal. The in-place path skips that step.
I found a potential fix for this issue. After a successful in-place restart, handleChangeRestart now re-initializes globalContentLayer. It uses the new settings and the new Vite watcher, reuses the existing data store (exposed through a new store getter on ContentLayer), then calls watchContentConfig() and sync(). A human should review this before merging. Note that server.restart() is also called directly in vite-plugin-actions.ts and vite-plugin-fonts.ts. Those calls skip this handler and probably have the same problem. The fix doesn't cover them.
Try this fix
You can test this fix right now without waiting for a release:
# astro
npm i https://pkg.pr.new/astro@d868633
If this fixes your issue, please leave a comment letting us know (for example
"confirmed, this fixes it"). A pull request will then be opened to get it merged.
Full Triage Report
Issue summary
After the dev server restarts in place because of a config change ("Configuration file updated. Restarting..."), edits to content collection entries are ignored until astro dev is restarted by hand. The reporter traces this to #16059 and calls it a regression of #12976 (fixed in #12984). They also say that on the very first astro dev run, writing .astro/settings.json triggers a restart right away, so content updates never work from the start.
Sandbox: repo main @ 4c1470a7f (astro 7.3.5), Node 22.23.2, pnpm 11.27.0, Linux, copy of examples/blog.
astro dev --background
Changed the title in src/content/blog/first-post.md. The log showed [glob-loader] Reloaded data from first-post.md and /blog/ showed the new title (baseline OK).
touch astro.config.mjs. The log showed Configuration file updated. Restarting... and [vite] server restarted.
Changed the title again. The log showed no loader output, and /blog/ still showed the old title after reloads. Bug reproduced.
Expected: content edits are picked up after a restart. Actual: edits are silently ignored.
I didn't test the first-run .astro/settings.json case, because settings.json was already in the copied example. The same root cause would apply to any restart.
Diagnosis (confidence: high)
restartContainerInPlace (packages/astro/src/core/dev/restart.ts ~L71–135) calls container.viteServer.restart(). Vite's restartServer closes the old server and its watcher, then runs Object.assign(server, newServer). The server object stays the same, but viteServer.watcher is a new FSWatcher.
globalContentLayer.init({ settings, logger, watcher, store }) runs only once at startup, in core/dev/dev.ts ~L120–127. ContentLayer wraps that watcher (createWatcherWrapper) and passes it to loaders. After a restart, loaders listen on the closed watcher, and #settings still holds the old settings.
fix: better handling of resync and restarts in content layer #12984 (commit 2d259cf) handled this by re-initializing the content layer in createContainer({ isRestart: true }) → syncInternal({ skip: { content: !isRestart }, watcher }). The in-place path no longer calls createContainer. After a restart, handleChangeRestart re-runs only setupContainer() and attachContentServerListeners().
attachDataStoreInvalidation is not affected, because it holds the same (mutated) viteServer object.
The restart handler already re-attaches the content types listeners. That shows the intent for content watching to survive restarts.
Fix
--- a/packages/astro/src/content/content-layer.ts+++ b/packages/astro/src/content/content-layer.ts@@ -79,6 +79,10 @@ export class ContentLayer {
return this.#queue.size > 0 || this.#queue.pending > 0;
}
+ get store() {+ return this.#store;+ }+--- a/packages/astro/src/core/dev/restart.ts+++ b/packages/astro/src/core/dev/restart.ts@@ -212,6 +212,7 @@
setupContainer();
await attachContentServerListeners(restart.container);
+ await restartContentLayer();
resolveRestart(null);
@@ -221,6 +222,21 @@+ // Vite's in-place restart closes the old file watcher, so loaders must be+ // re-registered on the new one, using the new settings.+ async function restartContentLayer() {+ const previousContentLayer = globalContentLayer.get();+ if (!previousContentLayer) return;+ const contentLayer = globalContentLayer.init({+ settings: restart.container.settings,+ logger,+ watcher: restart.container.viteServer.watcher,+ store: previousContentLayer.store,+ });+ contentLayer.watchContentConfig();+ await contentLayer.sync();+ }
Verification:
Blog repro: after each of two config restarts, the log showed [content] Syncing content / Synced content, then [glob-loader] Reloaded data from first-post.md, and /blog/ showed the new titles.
New test:packages/astro/test/content-layer-dev-restart.test.ts with fixture test/fixtures/content-layer-dev-restart/. It starts the dev server, edits astro.config.mjs, waits for the watcher to be replaced, edits an entry, and polls / for the new title. It fails without the fix and passes with it. It's an integration test rather than a unit test because the bug needs a real Vite server and watcher. The existing dev-restart.test.ts suite is skipped as flaky and doesn't set up a content layer.
Other checks:test/units/content-layer/** passes (116/116), content-collections-image-hmr.test.ts passes, tsc --noEmit and biome lint are clean.
Lockfile and changeset:pnpm-lock.yaml gains an importer entry for the new fixture. The changeset is .changeset/legal-streets-stand.md (astro: patch).
Notes:
The direct server.restart() calls in actions/vite-plugin-actions.ts:105 and assets/fonts/vite-plugin-fonts.ts:257 skip handleChangeRestart. They probably leave the content layer on a closed watcher too. A more general fix would re-initialize the content layer on every Vite restart, for example from a plugin's configureServer.
The sync() after a restart respects the Astro config digest. A changed config clears and reloads the store, the same as a fresh start.
This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.
- P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)triage: fix verifiedReporter confirmed the triage bot fix works
Activity
astro-factory commentedon Oct 3, 2026
Triage complete
triage: fix pendingpackages/astro/test/content-layer-dev-restart.test.tsastro devafter any config restart, and nothing in the log says so. The only workaround is to restartastro devby hand.Since #16059, a config change restarts the dev server in place with
viteServer.restart()(packages/astro/src/core/dev/restart.ts). This closes Vite's old file watcher and puts a new one on the same server object. The globalContentLayer, created once incore/dev/dev.ts, is never re-initialized. Its loaders (glob/file) stay subscribed to the closed watcher, and it keeps the settings from before the restart. The old restart path (the #12984 fix for #12976) re-initialized the content layer throughcreateContainer({ isRestart: true })→syncInternal. The in-place path skips that step.I found a potential fix for this issue. After a successful in-place restart,
handleChangeRestartnow re-initializesglobalContentLayer. It uses the new settings and the new Vite watcher, reuses the existing data store (exposed through a newstoregetter onContentLayer), then callswatchContentConfig()andsync(). A human should review this before merging. Note thatserver.restart()is also called directly invite-plugin-actions.tsandvite-plugin-fonts.ts. Those calls skip this handler and probably have the same problem. The fix doesn't cover them.Try this fix
You can test this fix right now without waiting for a release:
# astro npm i https://pkg.pr.new/astro@d868633If this fixes your issue, please leave a comment letting us know (for example
"confirmed, this fixes it"). A pull request will then be opened to get it merged.
Full Triage Report
Issue summary
After the dev server restarts in place because of a config change ("Configuration file updated. Restarting..."), edits to content collection entries are ignored until
astro devis restarted by hand. The reporter traces this to #16059 and calls it a regression of #12976 (fixed in #12984). They also say that on the very firstastro devrun, writing.astro/settings.jsontriggers a restart right away, so content updates never work from the start.Reporter environment: Astro 7.3.5, Node 26.0.0, macOS arm64, pnpm, static output,
@astrojs/mdx+@astrojs/sitemap(blog template).Reproduction
Sandbox: repo
main@4c1470a7f(astro 7.3.5), Node 22.23.2, pnpm 11.27.0, Linux, copy ofexamples/blog.astro dev --backgroundsrc/content/blog/first-post.md. The log showed[glob-loader] Reloaded data from first-post.mdand/blog/showed the new title (baseline OK).touch astro.config.mjs. The log showedConfiguration file updated. Restarting...and[vite] server restarted./blog/still showed the old title after reloads. Bug reproduced.Expected: content edits are picked up after a restart.
Actual: edits are silently ignored.
I didn't test the first-run
.astro/settings.jsoncase, becausesettings.jsonwas already in the copied example. The same root cause would apply to any restart.Diagnosis (confidence: high)
restartContainerInPlace(packages/astro/src/core/dev/restart.ts~L71–135) callscontainer.viteServer.restart(). Vite'srestartServercloses the old server and its watcher, then runsObject.assign(server, newServer). The server object stays the same, butviteServer.watcheris a new FSWatcher.globalContentLayer.init({ settings, logger, watcher, store })runs only once at startup, incore/dev/dev.ts~L120–127.ContentLayerwraps that watcher (createWatcherWrapper) and passes it to loaders. After a restart, loaders listen on the closed watcher, and#settingsstill holds the old settings.createContainer({ isRestart: true })→syncInternal({ skip: { content: !isRestart }, watcher }). The in-place path no longer callscreateContainer. After a restart,handleChangeRestartre-runs onlysetupContainer()andattachContentServerListeners().attachDataStoreInvalidationis not affected, because it holds the same (mutated)viteServerobject.Verification: bug (high confidence)
git blameonrestart.ts:116points to 6d5469e (Preserve Cloudflare miniflare instance across dev server config restarts #16059, "Preserve Cloudflare miniflare instance across dev server config restarts"). The content layer isn't mentioned there, and nothing in the code suggests that skipping the re-init was intentional.Fix
Verification:
[content] Syncing content/Synced content, then[glob-loader] Reloaded data from first-post.md, and/blog/showed the new titles.packages/astro/test/content-layer-dev-restart.test.tswith fixturetest/fixtures/content-layer-dev-restart/. It starts the dev server, editsastro.config.mjs, waits for the watcher to be replaced, edits an entry, and polls/for the new title. It fails without the fix and passes with it. It's an integration test rather than a unit test because the bug needs a real Vite server and watcher. The existingdev-restart.test.tssuite is skipped as flaky and doesn't set up a content layer.test/units/content-layer/**passes (116/116),content-collections-image-hmr.test.tspasses,tsc --noEmitand biome lint are clean.pnpm-lock.yamlgains an importer entry for the new fixture. The changeset is.changeset/legal-streets-stand.md(astro: patch).Notes:
server.restart()calls inactions/vite-plugin-actions.ts:105andassets/fonts/vite-plugin-fonts.ts:257skiphandleChangeRestart. They probably leave the content layer on a closed watcher too. A more general fix would re-initialize the content layer on every Vite restart, for example from a plugin'sconfigureServer.sync()after a restart respects the Astro config digest. A changed config clears and reloads the store, the same as a fresh start.This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.
matthewp commentedon Oct 5, 2026
Bot, I can confirm this fixes the issue.
astro-factory commentedon Oct 5, 2026
The fix has been verified! A pull request has been created: #18251