Only add flying-shuttle code when enabled (#8330)
Follow-up of #7536, small optimization / code removal when the feature is not enabled.
This commit is contained in:
parent
963726d68e
commit
2b62c33f25
4 changed files with 47 additions and 34 deletions
|
@ -147,6 +147,7 @@ export default class Router implements BaseRouter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @deprecated backwards compatibility even though it's a private method.
|
||||||
static _rewriteUrlForNextExport(url: string): string {
|
static _rewriteUrlForNextExport(url: string): string {
|
||||||
return rewriteUrlForNextExport(url)
|
return rewriteUrlForNextExport(url)
|
||||||
}
|
}
|
||||||
|
|
|
@ -541,6 +541,9 @@ export default async function getBaseWebpackConfig(
|
||||||
'process.env.NODE_ENV': JSON.stringify(webpackMode),
|
'process.env.NODE_ENV': JSON.stringify(webpackMode),
|
||||||
'process.crossOrigin': JSON.stringify(crossOrigin),
|
'process.crossOrigin': JSON.stringify(crossOrigin),
|
||||||
'process.browser': JSON.stringify(!isServer),
|
'process.browser': JSON.stringify(!isServer),
|
||||||
|
'process.env.__NEXT_EXPERIMENTAL_SELECTIVEPAGEBUILDING': JSON.stringify(
|
||||||
|
selectivePageBuilding
|
||||||
|
),
|
||||||
// This is used in client/dev-error-overlay/hot-dev-client.js to replace the dist directory
|
// This is used in client/dev-error-overlay/hot-dev-client.js to replace the dist directory
|
||||||
...(dev && !isServer
|
...(dev && !isServer
|
||||||
? {
|
? {
|
||||||
|
|
|
@ -162,8 +162,10 @@ export default async ({ webpackHMR: passedWebpackHMR } = {}) => {
|
||||||
await window.__NEXT_PRELOADREADY(dynamicIds)
|
await window.__NEXT_PRELOADREADY(dynamicIds)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dynamicBuildId === true) {
|
if (process.env.__NEXT_EXPERIMENTAL_SELECTIVEPAGEBUILDING) {
|
||||||
pageLoader.onDynamicBuildId()
|
if (dynamicBuildId === true) {
|
||||||
|
pageLoader.onDynamicBuildId()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
router = createRouter(page, query, asPath, {
|
router = createRouter(page, query, asPath, {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
/* global document, window */
|
/* global document, window */
|
||||||
import mitt from 'next-server/dist/lib/mitt'
|
import mitt from 'next-server/dist/lib/mitt'
|
||||||
import unfetch from 'unfetch'
|
|
||||||
|
|
||||||
function supportsPreload (el) {
|
function supportsPreload (el) {
|
||||||
try {
|
try {
|
||||||
|
@ -41,6 +40,39 @@ export default class PageLoader {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.env.__NEXT_EXPERIMENTAL_SELECTIVEPAGEBUILDING) {
|
||||||
|
this.promisedBuildId = Promise.resolve()
|
||||||
|
this.onDynamicBuildId = () => {
|
||||||
|
this.promisedBuildId = new Promise(resolve => {
|
||||||
|
const unfetch = require('unfetch')
|
||||||
|
unfetch(`${this.assetPrefix}/_next/static/HEAD_BUILD_ID`)
|
||||||
|
.then(res => {
|
||||||
|
if (res.ok) {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
const err = new Error('Failed to fetch HEAD buildId')
|
||||||
|
err.res = res
|
||||||
|
throw err
|
||||||
|
})
|
||||||
|
.then(res => res.text())
|
||||||
|
.then(buildId => {
|
||||||
|
this.buildId = buildId.trim()
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
// When this fails it's not a _huge_ deal, preload wont work and page
|
||||||
|
// navigation will 404, triggering a SSR refresh
|
||||||
|
console.warn(
|
||||||
|
'Failed to load BUILD_ID from server. ' +
|
||||||
|
'The following client-side page transition will likely 404 and cause a SSR.\n' +
|
||||||
|
'http://err.sh/zeit/next.js/head-build-id'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.then(resolve, resolve)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a promise for the dependencies for a particular route
|
// Returns a promise for the dependencies for a particular route
|
||||||
|
@ -111,37 +143,10 @@ export default class PageLoader {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onDynamicBuildId () {
|
|
||||||
this.promisedBuildId = new Promise(resolve => {
|
|
||||||
unfetch(`${this.assetPrefix}/_next/static/HEAD_BUILD_ID`)
|
|
||||||
.then(res => {
|
|
||||||
if (res.ok) {
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
const err = new Error('Failed to fetch HEAD buildId')
|
|
||||||
err.res = res
|
|
||||||
throw err
|
|
||||||
})
|
|
||||||
.then(res => res.text())
|
|
||||||
.then(buildId => {
|
|
||||||
this.buildId = buildId.trim()
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
// When this fails it's not a _huge_ deal, preload wont work and page
|
|
||||||
// navigation will 404, triggering a SSR refresh
|
|
||||||
console.warn(
|
|
||||||
'Failed to load BUILD_ID from server. ' +
|
|
||||||
'The following client-side page transition will likely 404 and cause a SSR.\n' +
|
|
||||||
'http://err.sh/zeit/next.js/head-build-id'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.then(resolve, resolve)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async loadRoute (route) {
|
async loadRoute (route) {
|
||||||
await this.promisedBuildId
|
if (process.env.__NEXT_EXPERIMENTAL_SELECTIVEPAGEBUILDING) {
|
||||||
|
await this.promisedBuildId
|
||||||
|
}
|
||||||
|
|
||||||
route = this.normalizeRoute(route)
|
route = this.normalizeRoute(route)
|
||||||
let scriptRoute = route === '/' ? '/index.js' : `${route}.js`
|
let scriptRoute = route === '/' ? '/index.js' : `${route}.js`
|
||||||
|
@ -206,7 +211,9 @@ export default class PageLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
async prefetch (route, isDependency) {
|
async prefetch (route, isDependency) {
|
||||||
await this.promisedBuildId
|
if (process.env.__NEXT_EXPERIMENTAL_SELECTIVEPAGEBUILDING) {
|
||||||
|
await this.promisedBuildId
|
||||||
|
}
|
||||||
|
|
||||||
route = this.normalizeRoute(route)
|
route = this.normalizeRoute(route)
|
||||||
let scriptRoute = `${route === '/' ? '/index' : route}.js`
|
let scriptRoute = `${route === '/' ? '/index' : route}.js`
|
||||||
|
|
Loading…
Reference in a new issue