fix(vercel): strip trailing slash from prerendered route overrides - #4412
fix(vercel): strip trailing slash from prerendered route overrides#4412thribhuvan003 wants to merge 5 commits into
Conversation
|
@thribhuvan003 is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis 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. ChangesVercel override mapping
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/presets/vercel/utils.ts (1)
397-413: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract 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.tsand 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
📒 Files selected for processing (3)
src/presets/vercel/utils.tstest/presets/vercel.test.tstest/unit/vercel-overrides.test.ts
…lash-overrides # Conflicts: # src/presets/vercel/utils.ts
commit: |
🔗 Linked issue
resolves #4392
❓ Type of change
📚 Description
prerendering a route with a trailing slash (e.g.
/slash/) emits a Build Output override whosepathkeeps 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