Skip to content

fix(assets): match directory index urls in isPublicAssetURL - #5140

Open
stantheman0128 wants to merge 2 commits into
nitrojs:mainfrom
stantheman0128:fix/5123-directory-index-asset
Open

stantheman0128 wants to merge 2 commits into
nitrojs:mainfrom
stantheman0128:fix/5123-directory-index-asset

Conversation

@stantheman0128

Copy link
Copy Markdown

Linked issue

Fixes #5123

Type of change

  • 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.

@stantheman0128
stantheman0128 requested a review from pi0 as a code owner November 16, 2026 17:12
@vercel

vercel Bot commented Nov 16, 2026

Copy link
Copy Markdown

@stantheman0128 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 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

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

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

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: 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
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.

isPublicAssetURL does not match directory URLs with an index.html without serveStatic

1 participant