Skip to content

Commit

Permalink
Merge branch 'canary' into fix/remove-rewrite-url-for-next-export
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Jan 4, 2020
2 parents f6eb575 + 72a0c55 commit 3f86542
Show file tree
Hide file tree
Showing 24 changed files with 69 additions and 437 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -88,7 +88,7 @@
"prettier": "1.19.1",
"react": "16.10.2",
"react-dom": "16.10.2",
"react-ssr-prepass": "1.0.7",
"react-ssr-prepass": "1.0.8",
"release": "6.0.1",
"request-promise-core": "1.1.2",
"rimraf": "2.6.3",
Expand Down
1 change: 0 additions & 1 deletion packages/next/build/entries.ts
Expand Up @@ -75,7 +75,6 @@ export function createEntrypoints(
buildId,
assetPrefix: config.assetPrefix,
generateEtags: config.generateEtags,
ampBindInitData: config.experimental.ampBindInitData,
canonicalBase: config.canonicalBase,
basePath: config.experimental.basePath,
}
Expand Down
29 changes: 0 additions & 29 deletions packages/next/build/webpack-config.ts
Expand Up @@ -445,21 +445,6 @@ export default async function getBaseWebpackConfig(
try {
res = resolveRequest(request, `${context}/`)
} catch (err) {
// This is a special case for the Next.js data experiment. This
// will be removed in the future.
// We're telling webpack to externalize a package that doesn't
// exist because we know it won't ever be used at runtime.
if (
request === 'react-ssr-prepass' &&
!config.experimental.ampBindInitData
) {
if (
context.replace(/\\/g, '/').includes('next-server/server')
) {
return callback(undefined, `commonjs ${request}`)
}
}

// If the request cannot be resolved, we need to tell webpack to
// "bundle" it so that webpack shows an error (that it cannot be
// resolved).
Expand Down Expand Up @@ -520,19 +505,6 @@ export default async function getBaseWebpackConfig(
// When the 'serverless' target is used all node_modules will be compiled into the output bundles
// So that the 'serverless' bundles have 0 runtime dependencies
'@ampproject/toolbox-optimizer', // except this one
(context, request, callback) => {
if (
request === 'react-ssr-prepass' &&
!config.experimental.ampBindInitData
) {
// if it's the Next.js' require mark it as external
// since it's not used
if (context.replace(/\\/g, '/').includes('next-server/server')) {
return callback(undefined, `commonjs ${request}`)
}
}
return callback()
},
],
optimization: {
checkWasmTypes: false,
Expand Down Expand Up @@ -868,7 +840,6 @@ export default async function getBaseWebpackConfig(
isDevelopment: dev,
isServer,
hasSupportCss: !!config.experimental.css,
hasExperimentalData: !!config.experimental.ampBindInitData,
assetPrefix: config.assetPrefix || '',
})

Expand Down
28 changes: 0 additions & 28 deletions packages/next/build/webpack/config/blocks/experiment-data.ts

This file was deleted.

9 changes: 1 addition & 8 deletions packages/next/build/webpack/config/index.ts
Expand Up @@ -2,7 +2,6 @@ import webpack from 'webpack'
import { base } from './blocks/base'
import { css } from './blocks/css'
import { ConfigurationContext, pipe } from './utils'
import { experimentData } from './blocks/experiment-data'

export async function build(
config: webpack.Configuration,
Expand All @@ -12,15 +11,13 @@ export async function build(
isDevelopment,
isServer,
hasSupportCss,
hasExperimentalData,
assetPrefix,
}: {
rootDirectory: string
customAppFile: string | null
isDevelopment: boolean
isServer: boolean
hasSupportCss: boolean
hasExperimentalData: boolean
assetPrefix: string
}
): Promise<webpack.Configuration> {
Expand All @@ -38,10 +35,6 @@ export async function build(
: '',
}

const fn = pipe(
base(ctx),
experimentData(hasExperimentalData, ctx),
css(hasSupportCss, ctx)
)
const fn = pipe(base(ctx), css(hasSupportCss, ctx))
return fn(config)
}
5 changes: 0 additions & 5 deletions packages/next/build/webpack/loaders/next-serverless-loader.ts
Expand Up @@ -18,7 +18,6 @@ export type ServerlessLoaderQuery = {
absoluteErrorPath: string
buildId: string
assetPrefix: string
ampBindInitData: boolean | string
generateEtags: string
canonicalBase: string
basePath: string
Expand All @@ -32,7 +31,6 @@ const nextServerlessLoader: loader.Loader = function() {
buildId,
canonicalBase,
assetPrefix,
ampBindInitData,
absoluteAppPath,
absoluteDocumentPath,
absoluteErrorPath,
Expand Down Expand Up @@ -213,8 +211,6 @@ const nextServerlessLoader: loader.Loader = function() {
canonicalBase: "${canonicalBase}",
buildId: "${buildId}",
assetPrefix: "${assetPrefix}",
ampBindInitData: ${ampBindInitData === true ||
ampBindInitData === 'true'},
..._renderOpts
}
let sprData = false
Expand All @@ -231,7 +227,6 @@ const nextServerlessLoader: loader.Loader = function() {
{
Component,
pageConfig: config,
dataOnly: req.headers && (req.headers.accept || '').indexOf('application/amp.bind+json') !== -1,
nextExport: fromExport
},
options,
Expand Down
13 changes: 3 additions & 10 deletions packages/next/client/index.js
Expand Up @@ -12,9 +12,7 @@ import {
import PageLoader from './page-loader'
import * as envConfig from '../next-server/lib/runtime-config'
import { HeadManagerContext } from '../next-server/lib/head-manager-context'
import { DataManagerContext } from '../next-server/lib/data-manager-context'
import { RouterContext } from '../next-server/lib/router-context'
import { DataManager } from '../next-server/lib/data-manager'
import { parse as parseQs, stringify as stringifyQs } from 'querystring'
import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic'

Expand Down Expand Up @@ -45,9 +43,6 @@ const {
dynamicIds,
} = data

const d = JSON.parse(window.__NEXT_DATA__.dataManager)
export const dataManager = new DataManager(d)

const prefix = assetPrefix || ''

// With dynamic assetPrefix it's no longer possible to set assetPrefix at the build time
Expand Down Expand Up @@ -384,11 +379,9 @@ function AppContainer({ children }) {
}
>
<RouterContext.Provider value={makePublicRouterInstance(router)}>
<DataManagerContext.Provider value={dataManager}>
<HeadManagerContext.Provider value={headManager.updateHead}>
{children}
</HeadManagerContext.Provider>
</DataManagerContext.Provider>
<HeadManagerContext.Provider value={headManager.updateHead}>
{children}
</HeadManagerContext.Provider>
</RouterContext.Provider>
</Container>
)
Expand Down
60 changes: 31 additions & 29 deletions packages/next/client/page-loader.js
Expand Up @@ -18,6 +18,16 @@ const relPrefetch =

const hasNoModule = 'noModule' in document.createElement('script')

function normalizeRoute(route) {
if (route[0] !== '/') {
throw new Error(`Route name should start with a "/", got "${route}"`)
}
route = route.replace(/\/index$/, '/')

if (route === '/') return route
return route.replace(/\/$/, '')
}

function appendLink(href, rel, as) {
return new Promise((res, rej, link) => {
link = document.createElement('link')
Expand Down Expand Up @@ -63,22 +73,12 @@ export default class PageLoader {
)
}

normalizeRoute(route) {
if (route[0] !== '/') {
throw new Error(`Route name should start with a "/", got "${route}"`)
}
route = route.replace(/\/index$/, '/')

if (route === '/') return route
return route.replace(/\/$/, '')
}

loadPage(route) {
return this.loadPageScript(route).then(v => v.page)
}

loadPageScript(route) {
route = this.normalizeRoute(route)
route = normalizeRoute(route)

return new Promise((resolve, reject) => {
const fire = ({ error, page, mod }) => {
Expand Down Expand Up @@ -139,8 +139,8 @@ export default class PageLoader {
})
}

async loadRoute(route) {
route = this.normalizeRoute(route)
loadRoute(route) {
route = normalizeRoute(route)
let scriptRoute = route === '/' ? '/index.js' : `${route}.js`

const url = `${this.assetPrefix}/_next/static/${encodeURIComponent(
Expand Down Expand Up @@ -203,20 +203,20 @@ export default class PageLoader {
register()
}

async prefetch(route, isDependency) {
prefetch(route, isDependency) {
// https://github.com/GoogleChromeLabs/quicklink/blob/453a661fa1fa940e2d2e044452398e38c67a98fb/src/index.mjs#L115-L118
// License: Apache 2.0
let cn
if ((cn = navigator.connection)) {
// Don't prefetch if using 2G or if Save-Data is enabled.
if (cn.saveData || /2g/.test(cn.effectiveType)) return
if (cn.saveData || /2g/.test(cn.effectiveType)) return Promise.resolve()
}

let url = this.assetPrefix
if (isDependency) {
url += route
} else {
route = this.normalizeRoute(route)
route = normalizeRoute(route)
this.prefetched[route] = true

let scriptRoute = `${route === '/' ? '/index' : route}.js`
Expand All @@ -229,22 +229,24 @@ export default class PageLoader {
)}/pages${encodeURI(scriptRoute)}`
}

if (
return Promise.all(
document.querySelector(
`link[rel="${relPrefetch}"][href^="${url}"], script[data-next-page="${route}"]`
)
) {
return
}

return Promise.all([
appendLink(url, relPrefetch, url.match(/\.css$/) ? 'style' : 'script'),
process.env.__NEXT_GRANULAR_CHUNKS &&
!isDependency &&
this.getDependencies(route).then(urls =>
Promise.all(urls.map(url => this.prefetch(url, true)))
),
]).then(
? []
: [
appendLink(
url,
relPrefetch,
url.match(/\.css$/) ? 'style' : 'script'
),
process.env.__NEXT_GRANULAR_CHUNKS &&
!isDependency &&
this.getDependencies(route).then(urls =>
Promise.all(urls.map(url => this.prefetch(url, true)))
),
]
).then(
// do not return any data
() => {},
// swallow prefetch errors
Expand Down
75 changes: 0 additions & 75 deletions packages/next/lib/data.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/next/next-server/lib/data-manager-context.ts

This file was deleted.

0 comments on commit 3f86542

Please sign in to comment.