-
-
Notifications
You must be signed in to change notification settings - Fork 886
fix(vercel): strip trailing slash from prerendered route overrides #4412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thribhuvan003
wants to merge
5
commits into
nitrojs:main
Choose a base branch
from
thribhuvan003:fix/vercel-trailing-slash-overrides
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+128
β26
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
44908da
fix(vercel): strip trailing slash from prerendered route overrides
thribhuvan003 bce6aba
fix(vercel): only emit prerender overrides vercel can match
RihanArfan 95248bb
test: update snapshots
RihanArfan 1b49316
Merge remote-tracking branch 'origin/main' into fix/vercel-trailing-sβ¦
RihanArfan 762a852
refactor(vercel): improve prerender override guard
RihanArfan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { defineHandler } from "nitro/h3"; | ||
|
|
||
| export default defineHandler((event) => { | ||
| event.res.headers.set("content-type", "text/html"); | ||
| return "<!DOCTYPE html><html><body>slash</body></html>"; | ||
| }); |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { getPrerenderOverrides } from "../../src/presets/vercel/utils.ts"; | ||
|
|
||
| describe("getPrerenderOverrides", () => { | ||
| it("returns no overrides without prerendered routes", () => { | ||
| expect(getPrerenderOverrides()).toEqual({}); | ||
| expect(getPrerenderOverrides([])).toEqual({}); | ||
| }); | ||
|
|
||
| it("skips files Vercel serves as directory indexes", () => { | ||
| expect( | ||
| getPrerenderOverrides([ | ||
| { route: "/", fileName: "/index.html" }, | ||
| { route: "/noslash", fileName: "/noslash/index.html" }, | ||
| { route: "/nested/deep/", fileName: "/nested/deep/index.html" }, | ||
| // Extensionless index, e.g. a non-HTML route with a trailing slash | ||
| { route: "/api/data/", fileName: "/api/data/index" }, | ||
| ]) | ||
| ).toEqual({}); | ||
| }); | ||
|
|
||
| // Keeping the trailing slash makes the path unmatchable (#4392) | ||
| it("does not emit a trailing-slash path", () => { | ||
| expect(getPrerenderOverrides([{ route: "/slash/", fileName: "/slash/index.html" }])).toEqual( | ||
| {} | ||
| ); | ||
| expect(getPrerenderOverrides([{ route: "/slash/", fileName: "/renamed/index.html" }])).toEqual({ | ||
| "renamed/index.html": { path: "slash" }, | ||
| }); | ||
| }); | ||
|
|
||
| it("overrides files that are not served at their route", () => { | ||
| expect( | ||
| getPrerenderOverrides([ | ||
| // `autoSubfolderIndex: false` | ||
| { route: "/about", fileName: "/about.html" }, | ||
| { route: "/blog/post", fileName: "/blog/post.html" }, | ||
| // `fileName` rewritten in a `prerender:generate` hook | ||
| { route: "/bar/", fileName: "/renamed/index.html" }, | ||
| ]) | ||
| ).toEqual({ | ||
| "about.html": { path: "about" }, | ||
| "blog/post.html": { path: "blog/post" }, | ||
| "renamed/index.html": { path: "bar" }, | ||
| }); | ||
| }); | ||
|
|
||
| // Vercel deletes the original entry when re-keying, so an override pointing a | ||
| // file at its own path would remove it from the deployment entirely | ||
| it("never points a file at its own path", () => { | ||
| const overrides = getPrerenderOverrides([ | ||
| { route: "/foo.html", fileName: "/foo.html" }, | ||
| { route: "/foo/index.html", fileName: "/foo/index.html" }, | ||
| { route: "/data.json", fileName: "/data.json" }, | ||
| { route: "/about", fileName: "/about.html" }, | ||
| ]); | ||
| for (const [file, { path }] of Object.entries(overrides)) { | ||
| expect(path).not.toBe(file); | ||
| } | ||
| expect(overrides).toEqual({ "about.html": { path: "about" } }); | ||
| }); | ||
|
|
||
| it("ignores routes without a fileName", () => { | ||
| expect(getPrerenderOverrides([{ route: "/skipped" }])).toEqual({}); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.