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(build): match directory public asset URLs with index.html - #5125
📖 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
Without serveStatic, presets such as cloudflare-module, cloudflare-pages and netlify-edge decided whether a request is a public asset via the generated isPublicAssetURL, which only checked the exact assets[id] key. A request for /docs or /docs/ therefore missed even when /docs/index.html had been emitted, and fell through to the Nitro app instead of the platform asset serving.
The generated helper now reuses hasAsset, which already resolves the id/index.html form (including its compressed variants) and the directory forms. No new lookup is added to non-asset requests: hasAsset is the same Map read the static middleware already performs before deciding whether to continue.
Scope kept to the shared virtual helper plus its unit test because #5087 is still touching this module; per-preset end-to-end coverage can follow in this PR or separately, whichever you prefer.
📋 Additional Notes
Unit regression in test/unit/public-assets.test.ts covers /docs, /docs/, a directory whose index is only present compressed, /, and negative cases (/docs/index, a missing directory, an API path). The test fails on the previous helper and passes after the change.
pnpm typecheck passes. test/unit/public-assets.test.ts on Windows still has four pre-existing File URL path must be absolute failures in the node-reader block, unrelated to this change; CI runs on Linux.
No actionable comments were generated in the recent review.
Walkthrough
isPublicAssetURL now uses hasAsset for asset checks. Tests cover directory URLs with index assets, including compressed-only indexes, and URLs that should not match.
Changes: Public asset matching
Layer / File(s)
Summary
Asset lookup and directory matching src/build/virtual/public-assets.ts, test/unit/public-assets.test.ts
isPublicAssetURL now checks hasAsset(id). Tests cover directory URL matching for index assets and reject /docs/index and /missing/.
nitrojs/nitro#5086: The issue discusses manifest ID lookup for directory index assets, which is the lookup behavior changed here.
Possibly related PRs
nitrojs/nitro#5079: Updates hasAsset to recognize directory forms for index assets, which this change uses.
nitrojs/nitro#5087: Changes the generated isPublicAssetURL lookup and the availability of hasAsset, so the lookup contract overlaps.
nitrojs/nitro#5082: Changes hasAsset behavior for index assets, which this change relies on.
Merge Risk: Minimal · up to c0bb1
The change makes directory URLs such as /docs match an emitted index.html, and unit tests cover that behavior. No concrete merge-blocking risk was identified.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title uses the conventional commit form (fix(build): ...). It names the change: directory public asset URLs now match an index.html asset. The changeset makes isPublicAssetURL call hasAsset, and t…
Description check
The description explains the bug: without serveStatic, directory requests such as /docs missed the exact assets[id] check. It states the fix reuses hasAsset, lists the unit test cases, and gives the l…
Linked Issues check
Issue #5123 asks that isPublicAssetURL match directory URLs (/docs, /docs/) when index.html exists, for presets without serveStatic. At the reviewed head, `src/build/virtual/public-assets.ts…
Out of Scope Changes check
The whole-PR diff against the merge base 0f2a7f4 changes one line in src/build/virtual/public-assets.ts (assets[id] lookup replaced by hasAsset(id)). The companion change is a unit test in `te…
Full details: Title check
Explanation
The title uses the conventional commit form (fix(build): ...). It names the change: directory public asset URLs now match an index.html asset. The changeset makes isPublicAssetURL call hasAsset, and the test covers directory matching, so the title describes the main change.
Full details: Description check
Explanation
The description explains the bug: without serveStatic, directory requests such as /docs missed the exact assets[id] check. It states the fix reuses hasAsset, lists the unit test cases, and gives the linked issue #5123. It relates directly to the changeset.
Full details: Linked Issues check
Explanation
Issue #5123 asks that isPublicAssetURL match directory URLs (/docs, /docs/) when index.html exists, for presets without serveStatic. At the reviewed head, src/build/virtual/public-assets.ts changes isPublicAssetURL from !!assets[id] to hasAsset(id). hasAsset reads a servable map built in the same generated module. That map registers dir and dir.slice(0, -1) for each */index.html asset, and it includes compressed variants through the _INDEX flag bits. The dir !== '/' guard avoids an empty-string key for the root. The change therefore covers the directory forms that the issue describes. The issue's concern about extra lookups on non-asset requests is addressed: hasAsset is a single Map.has call, and the static middleware already performs the same read. The issue states that per-preset tests are needed. This PR adds a shared unit regression in test/unit/public-assets.test.ts (per the PR description and the change summary) and does not add per-preset end-to-end tests. I did not inspect the test file directly. The per-preset gap is a test-coverage gap, not a missing behavior change, and the PR description states it openly. The core coding objective is implemented.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff against the merge base 0f2a7f4 changes one line in src/build/virtual/public-assets.ts (assets[id] lookup replaced by hasAsset(id)). The companion change is a unit test in test/unit/public-assets.test.ts that covers the directory cases named in the issue and the negative cases. Both changes implement the linked objective. No unrelated changes appear in the summary. The hasAsset behavior change also affects /foo.js when only /foo.js.gz exists, because the servable map registers the plain id. This follows the existing compressed-variant design in the same module and matches the intent of the issue, so it is not an unrelated change.
Finishing Touches
Generate unit tests (beta)
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: 9bd4f0ed-618a-4dc7-9d6a-9742615d5cea
Commits
Reviewing files that changed from the base of the PR and between 0f2a7f4 and c0bb1d8.
Files selected for processing: 2
src/build/virtual/public-assets.ts
test/unit/public-assets.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.
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 #5123
❓ Type of change
📚 Description
Without
serveStatic, presets such ascloudflare-module,cloudflare-pagesandnetlify-edgedecided whether a request is a public asset via the generatedisPublicAssetURL, which only checked the exactassets[id]key. A request for/docsor/docs/therefore missed even when/docs/index.htmlhad been emitted, and fell through to the Nitro app instead of the platform asset serving.The generated helper now reuses
hasAsset, which already resolves theid/index.htmlform (including its compressed variants) and the directory forms. No new lookup is added to non-asset requests:hasAssetis the sameMapread the static middleware already performs before deciding whether to continue.Scope kept to the shared virtual helper plus its unit test because #5087 is still touching this module; per-preset end-to-end coverage can follow in this PR or separately, whichever you prefer.
📋 Additional Notes
Unit regression in
test/unit/public-assets.test.tscovers/docs,/docs/, a directory whose index is only present compressed,/, and negative cases (/docs/index, a missing directory, an API path). The test fails on the previous helper and passes after the change.pnpm typecheckpasses.test/unit/public-assets.test.tson Windows still has four pre-existingFile URL path must be absolutefailures in the node-reader block, unrelated to this change; CI runs on Linux.