Skip to content

fix(dev): treat missing files in dev public assets manifest as absent - #5190

Open
MilindChatrabhuji wants to merge 1 commit into
nitrojs:mainfrom
MilindChatrabhuji:fix/dev-public-assets-missing-5122
Open

MilindChatrabhuji wants to merge 1 commit into
nitrojs:mainfrom
MilindChatrabhuji:fix/dev-public-assets-missing-5122

Conversation

@MilindChatrabhuji

Copy link
Copy Markdown

🔗 Linked issue

Resolves #5122

❓ Type of change

  • 📖 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.
  • Verified oxfmt --check, oxlint . (0 errors), tsc --noEmit --skipLibCheck, test/minimal/minimal.test.ts (24 passed), and test/presets/cloudflare-dev.test.ts (45 passed, 15 skipped on Windows).

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel

vercel Bot commented Nov 28, 2026

Copy link
Copy Markdown

@MilindChatrabhuji 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 Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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.
Remove public-directory watchers
src/build/build.ts, src/build/vite/_scan-watch.ts, test/unit/_scan-dirs.ts, test/unit/dev-scan-reload.test.ts, test/vite/scan-reload.test.ts
Build and Vite watchers no longer reload when public directories are removed. Tests observe the removed assets and the route sharing an asset URL.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • 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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed 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 Passed 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.

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: 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
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: treat missing files in the dev public assets manifest as absent

1 participant