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(assets): match directory index urls in isPublicAssetURL - #5140
Bug fix (a non-breaking change that fixes an issue)
Documentation (updates to the documentation, readme, or JSdoc annotations)
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
Cloudflare module, Cloudflare pages, and Netlify edge hand a request to platform assets only when isPublicAssetURL is true. That check matched an exact manifest key or a non-fallthrough public directory. /docs and /docs/ stayed false when the manifest had /docs/index.html, so the worker ran the app instead.
The helper now also accepts a non-empty id whose index.html is in the manifest. /, /docs, and /docs/ match. An empty id does not. A path that only has a compressed index, such as /blog/index.html.br, stays unmatched. The static server already falls through in that case when the client cannot accept the encoding, and treating that url as a public asset would turn the miss into a 404.
/foo.css stays false when the manifest only has the compressed files. Exact files and public directory prefixes are unchanged.
Checklist
I have linked an issue or discussion.
I have updated the documentation accordingly.
Written with Cursor Grok.
Verification: pnpm vitest run test/unit/public-assets.test.ts -t "virtual/public-assets lookup" passed, 64 tests. Before the fix, isPublicAssetURL("/") was false while /index.html was in the manifest. The node reader tests in that file already fail on this Windows machine with File URL path must be absolute. Preset builds were not run.
No actionable comments were generated in the recent review.
Walkthrough
isPublicAssetURL now recognizes a directory URL as public when the asset manifest contains its corresponding index.html URL. Unit tests cover directory URL variants and unmatched inputs.
Changes: Public asset matching
Layer / File(s)
Summary
Directory index matching and tests src/build/virtual/public-assets.ts, test/unit/public-assets.test.ts
isPublicAssetURL now checks for a corresponding index.html URL in the asset manifest. Tests cover /, /docs, /docs/, and /page/, plus unmatched paths, an empty URL, and /foo.css.
Issue 5086 discusses public asset manifest lookups for directory index.html IDs. This change adds matching for those IDs without changing the manifest shape.
Possibly related PRs
nitrojs/nitro#5087: It introduced the public asset manifest shape that isPublicAssetURL uses.
Merge Risk: Minimal · up to 7cd98
Directory URLs such as /docs and /docs/ now match when their index.html exists, so requests can reach platform assets. No merge-blocking defect was found. Percent-encoded directory names still do not match, as is already the case for file URLs.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "fix(assets): match directory index urls in isPublicAssetURL" follows the conventional commits format (type fix, scope assets, colon, description). It names the main change: isPublicAssetURL…
Description check
The description links issue #5123, marks the change as a bug fix, and explains the change. It states that isPublicAssetURL now accepts ids whose index.html is in the manifest, and it describes the edg…
Linked Issues check
Issue #5123 requires isPublicAssetURL to match directory URLs such as /docs and /docs/ when /docs/index.html is in the manifest, for presets without serveStatic. The diff in `src/build/virtu…
Out of Scope Changes check
The whole-PR diff against the merge base changes one helper in src/build/virtual/public-assets.ts (+2/-1) and adds unit test cases in test/unit/public-assets.test.ts. The helper change is the dire…
Full details: Title check
Explanation
The title "fix(assets): match directory index urls in isPublicAssetURL" follows the conventional commits format (type fix, scope assets, colon, description). It names the main change: isPublicAssetURL now matches directory URLs whose index.html is in the manifest.
Full details: Description check
Explanation
The description links issue #5123, marks the change as a bug fix, and explains the change. It states that isPublicAssetURL now accepts ids whose index.html is in the manifest, and it describes the edge cases (empty id, compressed-only index, /foo.css). It also lists the verification steps.
Full details: Linked Issues check
Explanation
Issue #5123 requires isPublicAssetURL to match directory URLs such as /docs and /docs/ when /docs/index.html is in the manifest, for presets without serveStatic. The diff in src/build/virtual/public-assets.ts adds a clause: !!id && !!assets[(id.endsWith('/') ? id : id + '/') + 'index.html']. For /, /docs, and /docs/, this lookup finds the index.html key and returns true. An empty id returns false, as the PR states. A path with only a compressed index, such as /blog/index.html.br, returns false because the lookup key is /blog/index.html.br/index.html, which is absent. /foo.css with only compressed files also returns false. Exact-file and public-directory-prefix checks are unchanged. The helper lives in the shared virtual module used by the Cloudflare module, Cloudflare Pages, and Netlify Edge presets, so the fix covers all three. The test file adds unit coverage for these cases. Limitation: the issue asks for tests per preset. The PR adds only shared-helper unit tests and no preset-level tests. The core requirement is met at the shared layer.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff against the merge base changes one helper in src/build/virtual/public-assets.ts (+2/-1) and adds unit test cases in test/unit/public-assets.test.ts. The helper change is the directory-index matching required by #5123. The tests cover that behavior and the negative cases. No unrelated files or behavior changes appear in the reviewed evidence.
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: b98939d9-ce37-4cc6-ac52-8dcf595dbe3f
Commits
Reviewing files that changed from the base of the PR and between 749b12b and 7cd98bb.
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 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
Fixes #5123
Type of change
Description
Cloudflare module, Cloudflare pages, and Netlify edge hand a request to platform assets only when
isPublicAssetURLis true. That check matched an exact manifest key or a non-fallthrough public directory./docsand/docs/stayed false when the manifest had/docs/index.html, so the worker ran the app instead.The helper now also accepts a non-empty id whose
index.htmlis in the manifest./,/docs, and/docs/match. An empty id does not. A path that only has a compressed index, such as/blog/index.html.br, stays unmatched. The static server already falls through in that case when the client cannot accept the encoding, and treating that url as a public asset would turn the miss into a 404./foo.cssstays false when the manifest only has the compressed files. Exact files and public directory prefixes are unchanged.Checklist
Written with Cursor Grok.
Verification:
pnpm vitest run test/unit/public-assets.test.ts -t "virtual/public-assets lookup"passed, 64 tests. Before the fix,isPublicAssetURL("/")was false while/index.htmlwas in the manifest. The node reader tests in that file already fail on this Windows machine withFile URL path must be absolute. Preset builds were not run.