Skip to content

fix(build): match directory public asset URLs with index.html - #5125

Closed
akshathayadav378-boop wants to merge 1 commit into
nitrojs:mainfrom
akshathayadav378-boop:fix/public-asset-directory-index
Closed

akshathayadav378-boop wants to merge 1 commit into
nitrojs:mainfrom
akshathayadav378-boop:fix/public-asset-directory-index

Conversation

@akshathayadav378-boop

Copy link
Copy Markdown

🔗 Linked issue

Resolves #5123

❓ 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

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.

@vercel

vercel Bot commented Nov 12, 2026

Copy link
Copy Markdown

@akshathayadav378-boop 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 12, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

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

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

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

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

2 participants