Skip to content

fix(vercel): strip trailing slash from prerendered route overrides - #4412

Open
thribhuvan003 wants to merge 5 commits into
nitrojs:mainfrom
thribhuvan003:fix/vercel-trailing-slash-overrides
Open

fix(vercel): strip trailing slash from prerendered route overrides#4412
thribhuvan003 wants to merge 5 commits into
nitrojs:mainfrom
thribhuvan003:fix/vercel-trailing-slash-overrides

Conversation

@thribhuvan003

Copy link
Copy Markdown
Contributor

🔗 Linked issue

resolves #4392

❓ 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

prerendering a route with a trailing slash (e.g. /slash/) emits a Build Output override whose path keeps the slash — "slash/index.html": { "path": "slash/" } — and vercel doesn't match override paths like that, so the route falls through to the server function instead of being served statically (repro + live deploy in #4392).

this strips the trailing slash the same way the leading one is already stripped, so the override becomes "path": "slash". the root route is unaffected (/ still maps to ""). extended the vercel:web preset test with a prerendered /slash/ route.

the same line exists on the v2 branch (src/presets/vercel/utils.ts:166) — happy to open a backport if useful.

📝 Checklist

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

@thribhuvan003
thribhuvan003 requested a review from pi0 as a code owner July 9, 2026 00:58
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

@thribhuvan003 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 Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 70adf396-d4e2-4075-8d7e-8000e1ecad32

📥 Commits

Reviewing files that changed from the base of the PR and between 1b49316 and 762a852.

📒 Files selected for processing (2)
  • src/presets/vercel/utils.ts
  • test/unit/vercel-overrides.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/unit/vercel-overrides.test.ts
  • src/presets/vercel/utils.ts

📝 Walkthrough

Walkthrough

This change centralizes Vercel prerender override generation, strips surrounding slashes, skips directory-index and invalid self-referential mappings, and adds preset and unit coverage for these cases.

Changes

Vercel override mapping

Layer / File(s) Summary
Override generation and build integration
src/presets/vercel/utils.ts
Adds getPrerenderOverrides, normalizes route paths, skips directory indexes and invalid mappings, and uses the helper during Vercel config generation.
Preset output regression coverage
test/presets/fixtures/slash.ts, test/presets/vercel.test.ts
Adds a /slash handler, prerenders /slash/, and updates config and function snapshots.
Override edge-case tests
test/unit/vercel-overrides.test.ts
Tests empty inputs, index routes, trailing slashes, rewritten filenames, self-referential entries, and missing filenames.

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

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is a valid conventional commit and clearly matches the Vercel trailing-slash fix.
Description check ✅ Passed The description directly explains the regression, fix, and test coverage, so it is clearly on-topic.
Linked Issues check ✅ Passed The code strips trailing slashes from prerender override paths and adds regression tests, matching #4392.
Out of Scope Changes check ✅ Passed All file changes support the Vercel override fix and tests; no unrelated changes are evident.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/presets/vercel/utils.ts (1)

397-413: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract this internal mapping helper into a dedicated module.

This adds more logic to an already 400+ LoC utility module. Move the helper and regexes to src/presets/vercel/_overrides.ts and import it directly.

As per coding guidelines, “Split logic across files; avoid long single-file modules (>200 LoC). Use _* prefix for internal files.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/presets/vercel/utils.ts` around lines 397 - 413, Extract
getPrerenderOverrides and its related SURROUNDING_SLASH_RE and INDEX_FILE_RE
definitions from the utility module into the internal
src/presets/vercel/_overrides.ts module, then import and use
getPrerenderOverrides from that module at its existing call sites. Preserve the
helper’s current mapping behavior and keep the underscore-prefixed module
internal.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/presets/vercel/utils.ts`:
- Around line 400-407: Normalize the route and file name in the
prerenderedRoutes loop before comparing them, then skip the override when the
normalized keys are equal via file === path, covering equivalent spellings such
as “/foo/” and “/foo”. Update the existing unit test for override generation to
include this self-targeting normalized case.

---

Nitpick comments:
In `@src/presets/vercel/utils.ts`:
- Around line 397-413: Extract getPrerenderOverrides and its related
SURROUNDING_SLASH_RE and INDEX_FILE_RE definitions from the utility module into
the internal src/presets/vercel/_overrides.ts module, then import and use
getPrerenderOverrides from that module at its existing call sites. Preserve the
helper’s current mapping behavior and keep the underscore-prefixed module
internal.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e3d53770-a9df-449e-97b5-e7e11ac02e4f

📥 Commits

Reviewing files that changed from the base of the PR and between 44908da and 95248bb.

📒 Files selected for processing (3)
  • src/presets/vercel/utils.ts
  • test/presets/vercel.test.ts
  • test/unit/vercel-overrides.test.ts

Comment thread src/presets/vercel/utils.ts Outdated
…lash-overrides

# Conflicts:
#	src/presets/vercel/utils.ts
@pkg-pr-new

pkg-pr-new Bot commented Jul 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4412

commit: 762a852

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.

Vercel preset emits trailing-slash override paths

2 participants