Commit 7e817cab authored by Tim Neutkens's avatar Tim Neutkens Committed by Joe Haddad

Remove rewriteUrlForNextExport from bundles when option is not enabled (#9946)

Co-authored-by: 's avatarJoe Haddad <timer150@gmail.com>
parent 72a0c557
...@@ -3,7 +3,6 @@ declare const __NEXT_DATA__: any ...@@ -3,7 +3,6 @@ declare const __NEXT_DATA__: any
import { resolve, parse, UrlObject } from 'url' import { resolve, parse, UrlObject } from 'url'
import React, { Component, Children } from 'react' import React, { Component, Children } from 'react'
import Router from './router' import Router from './router'
import { rewriteUrlForNextExport } from '../next-server/lib/router/rewrite-url-for-export'
import { import {
execOnce, execOnce,
formatWithValidation, formatWithValidation,
...@@ -264,6 +263,8 @@ class Link extends Component<LinkProps> { ...@@ -264,6 +263,8 @@ class Link extends Component<LinkProps> {
// Add the ending slash to the paths. So, we can serve the // Add the ending slash to the paths. So, we can serve the
// "<page>/index.html" directly. // "<page>/index.html" directly.
if (process.env.__NEXT_EXPORT_TRAILING_SLASH) { if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {
const rewriteUrlForNextExport = require('../next-server/lib/router/rewrite-url-for-export')
.rewriteUrlForNextExport
if ( if (
props.href && props.href &&
typeof __NEXT_DATA__ !== 'undefined' && typeof __NEXT_DATA__ !== 'undefined' &&
......
...@@ -13,7 +13,6 @@ import { ...@@ -13,7 +13,6 @@ import {
NextPageContext, NextPageContext,
SUPPORTS_PERFORMANCE_USER_TIMING, SUPPORTS_PERFORMANCE_USER_TIMING,
} from '../utils' } from '../utils'
import { rewriteUrlForNextExport } from './rewrite-url-for-export'
import { isDynamicRoute } from './utils/is-dynamic' import { isDynamicRoute } from './utils/is-dynamic'
import { getRouteMatcher } from './utils/route-matcher' import { getRouteMatcher } from './utils/route-matcher'
import { getRouteRegex } from './utils/route-regex' import { getRouteRegex } from './utils/route-regex'
...@@ -154,7 +153,13 @@ export default class Router implements BaseRouter { ...@@ -154,7 +153,13 @@ export default class Router implements BaseRouter {
// @deprecated backwards compatibility even though it's a private method. // @deprecated backwards compatibility even though it's a private method.
static _rewriteUrlForNextExport(url: string): string { static _rewriteUrlForNextExport(url: string): string {
if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {
const rewriteUrlForNextExport = require('./rewrite-url-for-export')
.rewriteUrlForNextExport
return rewriteUrlForNextExport(url) return rewriteUrlForNextExport(url)
} else {
return url
}
} }
onPopState = (e: PopStateEvent): void => { onPopState = (e: PopStateEvent): void => {
...@@ -275,6 +280,8 @@ export default class Router implements BaseRouter { ...@@ -275,6 +280,8 @@ export default class Router implements BaseRouter {
// Add the ending slash to the paths. So, we can serve the // Add the ending slash to the paths. So, we can serve the
// "<page>/index.html" directly for the SSR page. // "<page>/index.html" directly for the SSR page.
if (process.env.__NEXT_EXPORT_TRAILING_SLASH) { if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {
const rewriteUrlForNextExport = require('./rewrite-url-for-export')
.rewriteUrlForNextExport
// @ts-ignore this is temporarily global (attached to window) // @ts-ignore this is temporarily global (attached to window)
if (__NEXT_DATA__.nextExport) { if (__NEXT_DATA__.nextExport) {
as = rewriteUrlForNextExport(as) as = rewriteUrlForNextExport(as)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment