Skip to content

fix: refresh server-side content on file changes in dev - #3940

Open
larbish wants to merge 2 commits into
v4from
fix/dev-server-content-watch
Open

larbish wants to merge 2 commits into
v4from
fix/dev-server-content-watch

Conversation

@larbish

@larbish larbish commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)

📚 Description

In nuxt dev, the module process's instance, which serves pages through /__nuxt_content, watches files; Nitro's own content instance doesn't. Server-side content reads, including v3's queryCollection(event, …), return startup data and miss new files until restart.

When content.watch is enabled in dev, the module registers a Nitro plugin that calls watch() on Nitro's content instance and stops it on the close hook.

Evidence

With a server route reading content in nuxt dev:

// server/api/page.ts
export default defineEventHandler(async () => {
  const page = await content.get('/')
  return { title: page?.data.title }
})

After changing content/index.md's title from Before to After and adding content/new.md:

Before (origin/v4):

page (SSR):           <h1>After</h1>
/api/page:            {"title":"Before"}
/api/page?path=/new:  {"title":null}

After:

page (SSR):           <h1>After</h1>
/api/page:            {"title":"After"}
/api/page?path=/new:  {"title":"New page"}

The new test in test/dev.test.ts (reading /api/doc) fails on origin/v4:

× updates server-side `content` reads when a file is added, changed and removed 10032ms
AssertionError: expected null to be 'Added' // Object.is equality
Caused by: Error: Matcher did not succeed in time.

With the fix:

Test Files  1 passed (1)
     Tests  3 passed (3)

Notes

In dev, each file change is parsed twice: once in the module process and once in Nitro. Sharing one instance across the worker boundary would require an RPC layer.

ELI5

During development, pages and server routes read from separate copies of your content. Server routes weren't watching for file changes, so they kept returning startup content until restart; now they update when files change too.

🤖 Generated with Amp, reviewed by @larbish before opening.

@vercel

vercel Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
content Error Error Nov 30, 2026 4:56pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Development setup registers a Nitro plugin that starts content watching and runs its cleanup when Nitro closes. A fixture API handler returns a document title or null. A dev-mode test checks the API response before a file exists, after it is added and changed, and after it is removed.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · up to 6cf65

This change makes server routes, middleware and plugins see file changes during nuxt dev. It affects only development mode and is easily reversible. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: server-side content reads in dev now refresh when files change. It is a fix, and the changeset adds a dev-only Nitro plugin that watches Nitro's own content instance. …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description states the bug (server-side content reads return startup data and miss new files in nuxt dev), the cause (Nitro's own content instance does not watch files), and the fix (a dev-only Ni…
Full details: Title check

Explanation

The title names the main change: server-side content reads in dev now refresh when files change. It is a fix, and the changeset adds a dev-only Nitro plugin that watches Nitro's own content instance. The title is short, specific, and matches the changes described in the summary and objectives.

Full details: Description check

Explanation

The description states the bug (server-side content reads return startup data and miss new files in nuxt dev), the cause (Nitro's own content instance does not watch files), and the fix (a dev-only Nitro plugin calls watch() on that instance and stops it on close). It also gives before and after evidence, test results, and notes on the double parsing. This matches the changeset: the module registers the watch plugin, the new watch.dev.ts file implements it, and the test and fixture cover the scenario.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8e22514d-3cab-4c34-8be6-66aaabf2189f
Commits

Reviewing files that changed from the base of the PR and between ffd5a74 and 6cf6563.

Files selected for processing: 1

  • src/runtime/server/internal/watch.dev.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/content@3940

commit: 6cf6563

This branch had an error being deployed

1 failed deployment
Preview — 6cf65635 Deployed Nov 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant