Skip to content

Commit

Permalink
Remove rewriteUrlForNextExport from bundles when option is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Jan 4, 2020
1 parent 8898b85 commit f6eb575
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
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

0 comments on commit f6eb575

Please sign in to comment.