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
fix: refresh server-side content on file changes in dev - #3940
🐞 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.
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.
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.
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: 4
Check name
Status
Explanation
Title check
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
❓ Type of change
📚 Description
In
nuxt dev, the module process's instance, which serves pages through/__nuxt_content, watches files; Nitro's owncontentinstance doesn't. Server-sidecontentreads, including v3'squeryCollection(event, …), return startup data and miss new files until restart.When
content.watchis enabled in dev, the module registers a Nitro plugin that callswatch()on Nitro'scontentinstance and stops it on theclosehook.Evidence
With a server route reading
contentinnuxt dev:After changing
content/index.md's title fromBeforetoAfterand addingcontent/new.md:Before (
origin/v4):After:
The new test in
test/dev.test.ts(reading/api/doc) fails onorigin/v4:With the fix:
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.