Skip to content
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

Remove rewriteUrlForNextExport from bundles when option is not enabled #9946

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/next/client/link.tsx
Expand Up @@ -3,7 +3,6 @@ declare const __NEXT_DATA__: any
import { resolve, parse, UrlObject } from 'url'
import React, { Component, Children } from 'react'
import Router from './router'
import { rewriteUrlForNextExport } from '../next-server/lib/router/rewrite-url-for-export'
import {
execOnce,
formatWithValidation,
Expand Down Expand Up @@ -264,6 +263,8 @@ class Link extends Component<LinkProps> {
// Add the ending slash to the paths. So, we can serve the
// "<page>/index.html" directly.
if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {
const rewriteUrlForNextExport = require('../next-server/lib/router/rewrite-url-for-export')
.rewriteUrlForNextExport
if (
props.href &&
typeof __NEXT_DATA__ !== 'undefined' &&
Expand Down
11 changes: 9 additions & 2 deletions packages/next/next-server/lib/router/router.ts
Expand Up @@ -13,7 +13,6 @@ import {
NextPageContext,
SUPPORTS_PERFORMANCE_USER_TIMING,
} from '../utils'
import { rewriteUrlForNextExport } from './rewrite-url-for-export'
import { isDynamicRoute } from './utils/is-dynamic'
import { getRouteMatcher } from './utils/route-matcher'
import { getRouteRegex } from './utils/route-regex'
Expand Down Expand Up @@ -154,7 +153,13 @@ export default class Router implements BaseRouter {

// @deprecated backwards compatibility even though it's a private method.
static _rewriteUrlForNextExport(url: string): string {
return rewriteUrlForNextExport(url)
if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {
const rewriteUrlForNextExport = require('./rewrite-url-for-export')
.rewriteUrlForNextExport
return rewriteUrlForNextExport(url)
} else {
return url
}
}

onPopState = (e: PopStateEvent): void => {
Expand Down Expand Up @@ -275,6 +280,8 @@ export default class Router implements BaseRouter {
// Add the ending slash to the paths. So, we can serve the
// "<page>/index.html" directly for the SSR page.
if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {
const rewriteUrlForNextExport = require('./rewrite-url-for-export')
.rewriteUrlForNextExport
// @ts-ignore this is temporarily global (attached to window)
if (__NEXT_DATA__.nextExport) {
as = rewriteUrlForNextExport(as)
Expand Down