forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid pulling extra code in the bundles for trailingSlash logic (verc…
…el#14696) * avoid pulling code in the bundle for `trailingSlash` logic when it's not enabled * avoid cloning the url an extra time if normalizing the path doesn't change it
- Loading branch information
Showing
6 changed files
with
37 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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 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 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,25 @@ | ||
import { UrlObject } from 'url' | ||
|
||
export function removePathTrailingSlash(path: string): string { | ||
return path.endsWith('/') && path !== '/' ? path.slice(0, -1) : path | ||
} | ||
|
||
const normalizePathTrailingSlash = process.env.__NEXT_TRAILING_SLASH | ||
? (path: string): string => { | ||
if (/\.[^/]+\/?$/.test(path)) { | ||
return removePathTrailingSlash(path) | ||
} else if (path.endsWith('/')) { | ||
return path | ||
} else { | ||
return path + '/' | ||
} | ||
} | ||
: removePathTrailingSlash | ||
|
||
export function normalizeTrailingSlash(url: UrlObject): UrlObject { | ||
const normalizedPath = | ||
url.pathname && normalizePathTrailingSlash(url.pathname) | ||
return url.pathname === normalizedPath | ||
? url | ||
: Object.assign({}, url, { pathname: normalizedPath }) | ||
} |
20 changes: 0 additions & 20 deletions
20
packages/next/next-server/lib/router/normalize-trailing-slash.ts
This file was deleted.
Oops, something went wrong.
This file contains 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 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