Skip to content

fix(dev): rebuild manifest when public directory is added - #5210

Merged
pi0 merged 1 commit into
nitrojs:mainfrom
SHANNWD:fix/watch-public-dirs-adddir-5200
Dec 4, 2026
Merged

pi0 merged 1 commit into
nitrojs:mainfrom
SHANNWD:fix/watch-public-dirs-adddir-5200

Conversation

@SHANNWD

@SHANNWD SHANNWD commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #5200

watchPublicDirs (and Vite's watchScanDirs) previously only triggered a rebuild on unlinkDir for public/ directories, so removing and recreating public/ left the dev worker's #nitro/virtual/public-assets-data manifest stale and serverFetch returning 404 even while external disk requests worked.

Changes:

  • Trigger build:reload on both addDir and unlinkDir for publicDirs in watchPublicDirs() (src/build/build.ts), and onChange() in watchScanDirs() (src/build/vite/_scan-watch.ts).
  • Add a regression test in test/unit/dev-scan-reload.test.ts verifying serverFetch serves recreated public/ assets after public/ is removed and recreated.

@SHANNWD
SHANNWD requested a review from pi0 as a code owner December 4, 2026 16:30
@vercel

vercel Bot commented Dec 4, 2026

Copy link
Copy Markdown

@SHANNWD is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Public-directory watchers now handle both directory additions and removals. A dev-server test checks that an asset becomes unavailable after removal and is served again after restoration.

Changes: Public directory reload handling

Layer / File(s) Summary
Watcher reload behavior
src/build/build.ts, src/build/vite/_scan-watch.ts, test/unit/dev-scan-reload.test.ts
Both watcher paths trigger reload handling for matching public-directory additions and removals. The dev-server test checks asset availability before removal, after removal, and after the asset is recreated.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • Issue 5122 describes stale public-asset behavior related to the watcher logic changed here.

Possibly related PRs

  • nitrojs/nitro#5190: Changes the same watcher behavior and manifest lookup for stale public assets.
  • nitrojs/nitro#5120: Introduces the public-directory watchers that this change extends to handle additions.
  • nitrojs/nitro#5208: Changes the same watcher and adds a regression test for the same stale-manifest issue.
Merge Risk: Minimal · up to aacca

In development, recreating the public directory now triggers a reload, so assets are served again through serverFetch without an unrelated source edit. No concrete merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title uses conventional commit format (fix(dev): prefix with scope and description). It names the main change: the manifest is rebuilt when a public directory is added. The changeset adds addDir h…
Description check Passed The description is related to the changeset. It states the fix for issue #5200, names the watchers changed in src/build/build.ts and src/build/vite/_scan-watch.ts, and lists the regression test added …
Linked Issues check Passed [#5200] The issue requires that recreating public/ restores serverFetch access to the asset without an unrelated source edit. The reported cause is that watchPublicDirs in src/build/build.ts r…
Out of Scope Changes check Passed All changed code stays within the scope of #5200. The src/build/build.ts change widens the existing unlinkDir handler to addDir and unlinkDir for the same public dir set. The `src/build/vite/_…
Full details: Title check

Explanation

The title uses conventional commit format (fix(dev): prefix with scope and description). It names the main change: the manifest is rebuilt when a public directory is added. The changeset adds addDir handling alongside unlinkDir in both watchers, so the title matches the main change. The description also states the rebuild now runs on addDir as well as unlinkDir.

Full details: Description check

Explanation

The description is related to the changeset. It states the fix for issue #5200, names the watchers changed in src/build/build.ts and src/build/vite/_scan-watch.ts, and lists the regression test added in test/unit/dev-scan-reload.test.ts.

Full details: Linked Issues check

Explanation

[#5200] The issue requires that recreating public/ restores serverFetch access to the asset without an unrelated source edit. The reported cause is that watchPublicDirs in src/build/build.ts rebuilds only on unlinkDir, so the dev worker manifest is not refreshed when public/ is recreated. At the reviewed head, watchPublicDirs handles addDir as well as unlinkDir for configured public dirs and calls build:reload. This is the same reload path the issue reports as working after a source-triggered rebuild. The Vite path in src/build/vite/_scan-watch.ts receives the same change, so watchScanDirs also reloads on addDir for public dirs. The PR adds a regression test in test/unit/dev-scan-reload.test.ts that checks serverFetch after public/ is removed and recreated. I did not run that test, and I read the test only from the PR summary. The issue makes no Vite or production acceptance criteria, so the Vite change is not required by the issue. Its behavior is still consistent with the fix.

Full details: Out of Scope Changes check

Explanation

All changed code stays within the scope of #5200. The src/build/build.ts change widens the existing unlinkDir handler to addDir and unlinkDir for the same public dir set. The src/build/vite/_scan-watch.ts change makes the matching edit in the Vite watcher. Both doc-comment edits describe the same behavior. The regression test in test/unit/dev-scan-reload.test.ts covers the reported case. No unrelated changes were identified in the diff inspection. I did not inspect the test file contents directly.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • 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: 799c2500-dce4-4637-8b1b-396a6943e032
Commits

Reviewing files that changed from the base of the PR and between ccba20b and aaccaf3.

Files selected for processing: 3

  • src/build/build.ts
  • src/build/vite/_scan-watch.ts
  • test/unit/dev-scan-reload.test.ts

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

@pi0
pi0 merged commit 241119a into nitrojs:main Dec 4, 2026
4 of 5 checks passed
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.

Dev: recreating public/ restores external assets but leaves serverFetch returning 404

2 participants