Skip to content

Content collection changes ignored after dev server restarts on config change #18216

Closed

Description

@Leksat

Astro Info

Astro                    v7.3.5
Node                     v26.0.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             @astrojs/mdx
                         @astrojs/sitemap

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:

  1. npm create astro@latest -- --template blog, then astro dev
  2. Edit the title in src/content/blog/first-post.md: /blog updates, the log shows [glob-loader] Reloaded data from first-post.md
  3. touch astro.config.mjs: the log shows Configuration file updated. Restarting...
  4. 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.

Link to Minimal Reproducible Example

https://astro.new/blog?on=github

Participation

  • I am willing to submit a pull request for this issue.

Activity

  1. added
    triage: in progress
    on Oct 3, 2026
  2. astro-factory commented on Oct 3, 2026

    @astro-factory
    Contributor

    Triage complete

    • Prepare the workspace: ready
    • Install dependencies: complete
    • Build the project: complete
    • Reproduce the issue: confirmed
    • Diagnose the cause: high confidence
    • Verify the diagnosis: bug
    • Attempt a fix: verified
    • Publish the result: set triage: fix pending

    • Reproduced: Yes
    • Exploration: Yes — View branch
    • 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.

    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 of examples/blog.

    1. astro dev --background
    2. 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).
    3. touch astro.config.mjs. The log showed Configuration file updated. Restarting... and [vite] server restarted.
    4. 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.

    Verification: bug (high confidence)

    • git blame on restart.ts:116 points 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.
    • 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.

  3. added
    - P4: important
    pkg: astro
    triage: fix pending
    and removed
    triage: in progress
    on Oct 3, 2026
  4. self-assigned this
    on Oct 5, 2026
  5. matthewp commented on Oct 5, 2026

    @matthewp
    Contributor

    Bot, I can confirm this fixes the issue.

  6. added
    triage: fix verified
    and removed
    triage: fix pending
    on Oct 5, 2026
  7. astro-factory commented on Oct 5, 2026

    @astro-factory
    Contributor

    The fix has been verified! A pull request has been created: #18251

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

- P4: importantpkg: astrotriage: fix verified

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions