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(dev): treat missing files in dev public assets manifest as absent - #5190
📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
🐞 Bug fix (a non-breaking change that fixes an issue)
👌 Enhancement (improving an existing functionality like performance)
✨ New feature (a non-breaking change that adds functionality)
🧹 Chore (updates to the build process or auxiliary tools and libraries)
⚠️ Breaking change (fix or feature that would cause existing functionality to change)
📚 Description
In development (dev with the Node asset reader), the generated #nitro/virtual/public-assets module now checks existsSync(asset.path) against assets entries at lookup time (getAsset, isPublicAssetURL, hasAsset, hasEncodedVariants, resolveAsset):
Deleting a single file in public/ or removing a whole public/ directory immediately makes the static middleware treat it as absent and fall through to matching app routes without waiting for a worker rebuild.
Removing only a compressed variant drops Vary / encoded selection while keeping the plain file servable, and re-creating a deleted file makes it resolvable again dynamically.
Removes watchPublicDirs from src/build/build.ts and the public/ directory watcher branch from src/build/vite/_scan-watch.ts.
Production output (!nitro.options.dev) and non-Node static handlers remain unchanged.
Tests
Updated publicAssetCase in test/unit/_scan-dirs.ts (covered by test/unit/dev-scan-reload.test.ts on rolldown + rollup and test/vite/scan-reload.test.ts) to also verify fallthrough to a route behind a deleted public file both via direct fetch and serverFetch.
Added unit tests in test/unit/public-assets.test.ts for live dev manifest lookup across variant deletion, full file/index deletion, non-fallthrough base URLs, and re-creation.
No actionable comments were generated in the recent review.
Walkthrough
Development public-asset lookups check current file presence. Public-directory removal watchers are removed. Tests cover deleted assets, route observations, and recreated assets.
Changes: Development public assets
Layer / File(s)
Summary
Check current asset presence src/build/virtual/public-assets.ts, test/unit/_public-assets.ts, test/unit/public-assets.test.ts
In development with the node handler, asset lookups and encoding checks use current disk presence. Tests cover missing files, compressed variants, directory indexes, and recreated assets.
nitrojs/nitro#5120: Adds the public-directory watcher behavior that this PR removes.
nitrojs/nitro#5121: Changes the development public-assets reader and adds deleted-asset tests also touched by this PR.
nitrojs/nitro#5087: Restructures the manifest and reader contract used by this PR.
Suggested labels:bug, dev
Merge Risk: Low · up to f0b57
In development, deleting a public directory that shadows a same-named file in another public directory can leave that URL falling through to routes until the next reload. This is a narrow edge case with a safe fallback, so the change is mergeable with owner awareness.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title follows the conventional commits format with the type "fix" and scope "dev". It states the main change: missing files in the dev public assets manifest are now treated as absent. The changes…
Description check
The description links issue #5122 and explains the lookup-time existence checks in the generated public-assets module. It also covers the removal of the public directory watcher, the test updates, and…
Linked Issues check
Directly linked issue #5122 requires that dev manifest entries whose files no longer exist be treated as absent, in both isPublicAssetURL and asset lookup, and that watchPublicDirs and the `_scan-…
Out of Scope Changes check
All changed areas map to #5122 or its supporting verification: - src/build/virtual/public-assets.ts: implements the live existence checks required by #5122. Changes are gated by dev and node han…
Full details: Title check
Explanation
The title follows the conventional commits format with the type "fix" and scope "dev". It states the main change: missing files in the dev public assets manifest are now treated as absent. The changeset matches this, since the public-assets helpers now check file existence at lookup time in development.
Full details: Description check
Explanation
The description links issue #5122 and explains the lookup-time existence checks in the generated public-assets module. It also covers the removal of the public directory watcher, the test updates, and the validation steps. This matches the changeset.
Full details: Linked Issues check
Explanation
Directly linked issue #5122 requires that dev manifest entries whose files no longer exist be treated as absent, in both isPublicAssetURL and asset lookup, and that watchPublicDirs and the _scan-watch.ts public-dir branch be removed.
Evidence at head:
src/build/virtual/public-assets.ts: when nitro.options.dev and the handler is node, the generated module imports existsSync from node:fs and defines _hasFile(assetId). isPublicAssetURL and getAsset now use _hasFile. hasAsset, hasEncodedVariants, and resolveAsset use _liveFlags, which keeps only plain, compressed, and index.html variants whose files exist. This covers single-file deletion, directory deletion, and variant-only deletion.
src/build/build.ts and src/build/vite/_scan-watch.ts: the public/ watcher and the unlinkDir public-dir reload branch are removed, as the issue requests.
Production output (dev false) and non-node handlers keep the previous assets[id] and servable-map logic.
Tests: the PR updates publicAssetCase (route fallthrough behind a deleted public file) and adds live-lookup tests in test/unit/public-assets.test.ts. The PR reports passing runs of the related suites. I did not run the tests. The static reading supports the requirement behavior.
Not covered by this issue: creating a new public file still requires a manifest rebuild. The issue does not request this.
Full details: Out of Scope Changes check
Explanation
All changed areas map to #5122 or its supporting verification:
src/build/virtual/public-assets.ts: implements the live existence checks required by #5122. Changes are gated by dev and node handler, so other paths are unchanged.
src/build/build.ts and src/build/vite/_scan-watch.ts: removal of watchPublicDirs and the public-dir watcher branch, explicitly requested by #5122.
test/unit/_public-assets.ts: adds optional dev and existsSync parameters to the test helper. This supports the new live-lookup tests.
test/unit/_scan-dirs.ts, test/unit/dev-scan-reload.test.ts, test/vite/scan-reload.test.ts: extend the deleted-public-asset case to check route fallthrough and removal of every listed file, as #5122 requests.
test/unit/public-assets.test.ts: new tests for variant deletion, file and index deletion, non-fallthrough base URLs, and recreation.
No unrelated functional change was found in the reviewed summary or in the inspected hunks.
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: a2a0a998-a010-4aa5-9912-a079153882bd
Commits
Reviewing files that changed from the base of the PR and between 925c135 and f0b57fd.
Files selected for processing: 8
src/build/build.ts
src/build/virtual/public-assets.ts
src/build/vite/_scan-watch.ts
test/unit/_public-assets.ts
test/unit/_scan-dirs.ts
test/unit/dev-scan-reload.test.ts
test/unit/public-assets.test.ts
test/vite/scan-reload.test.ts
Files with no reviewable changes: 1
src/build/build.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.
This branch has not been deployed
No deployments
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.
🔗 Linked issue
Resolves #5122
❓ Type of change
📚 Description
In development (
devwith the Node asset reader), the generated#nitro/virtual/public-assetsmodule now checksexistsSync(asset.path)againstassetsentries at lookup time (getAsset,isPublicAssetURL,hasAsset,hasEncodedVariants,resolveAsset):public/or removing a wholepublic/directory immediately makes the static middleware treat it as absent and fall through to matching app routes without waiting for a worker rebuild.Vary/ encoded selection while keeping the plain file servable, and re-creating a deleted file makes it resolvable again dynamically.watchPublicDirsfromsrc/build/build.tsand thepublic/directory watcher branch fromsrc/build/vite/_scan-watch.ts.!nitro.options.dev) and non-Node static handlers remain unchanged.Tests
publicAssetCaseintest/unit/_scan-dirs.ts(covered bytest/unit/dev-scan-reload.test.tsonrolldown+rollupandtest/vite/scan-reload.test.ts) to also verify fallthrough to a route behind a deleted public file both via direct fetch andserverFetch.test/unit/public-assets.test.tsfor live dev manifest lookup across variant deletion, full file/index deletion, non-fallthrough base URLs, and re-creation.oxfmt --check,oxlint .(0 errors),tsc --noEmit --skipLibCheck,test/minimal/minimal.test.ts(24 passed), andtest/presets/cloudflare-dev.test.ts(45 passed, 15 skipped on Windows).📝 Checklist