Skip to content

Commit

Permalink
Merge branch 'canary' into next-api-handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer authored Feb 19, 2020
2 parents ec9705b + db04cc5 commit 9f2ec82
Show file tree
Hide file tree
Showing 30 changed files with 65 additions and 121 deletions.
2 changes: 1 addition & 1 deletion examples/with-graphql-faunadb/scripts/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ readline.question(`Please provide the FaunaDB admin key\n`, adminKey => {
privileges: [
{
resource: q.Collection('GuestbookEntry'),
actions: { read: true, write: true },
actions: { read: true, write: true, create: true },
},
{
resource: q.Index('entries'),
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "9.2.2"
"version": "9.2.3-canary.1"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "9.2.2",
"version": "9.2.3-canary.1",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "9.2.2",
"version": "9.2.3-canary.1",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "9.2.2",
"version": "9.2.3-canary.1",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-google-analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-google-analytics",
"version": "9.2.2",
"version": "9.2.3-canary.1",
"nextjs": {
"name": "Google Analytics",
"required-env": [
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-material-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-material-ui",
"version": "9.2.2",
"version": "9.2.3-canary.1",
"nextjs": {
"name": "Material UI",
"required-env": []
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-sentry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-sentry",
"version": "9.2.2",
"version": "9.2.3-canary.1",
"nextjs": {
"name": "Sentry",
"required-env": [
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "9.2.2",
"version": "9.2.3-canary.1",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
6 changes: 2 additions & 4 deletions packages/next/build/babel/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ module.exports = (
const supportsESM = api.caller(supportsStaticESM)
const isServer = api.caller((caller: any) => !!caller && caller.isServer)
const isModern = api.caller((caller: any) => !!caller && caller.isModern)
const isPolyfillsOptimization = api.caller(
(caller: any) => !!caller && caller.polyfillsOptimization
)

const isLaxModern =
isModern ||
(options['preset-env']?.targets &&
Expand Down Expand Up @@ -155,7 +153,7 @@ module.exports = (
!isServer && [
require('@babel/plugin-transform-runtime'),
{
corejs: isPolyfillsOptimization ? false : 2,
corejs: false,
helpers: true,
regenerator: true,
useESModules: supportsESM && presetEnvConfig.modules !== 'commonjs',
Expand Down
44 changes: 4 additions & 40 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ const escapePathVariables = (value: any) => {
: value
}

function getOptimizedAliases(
isServer: boolean,
polyfillsOptimization: boolean
): { [pkg: string]: string } {
function getOptimizedAliases(isServer: boolean): { [pkg: string]: string } {
if (isServer) {
return {}
}
Expand All @@ -68,12 +65,6 @@ function getOptimizedAliases(
const shimAssign = path.join(__dirname, 'polyfills', 'object.assign')
return Object.assign(
{},
// Polyfill: Window#fetch
polyfillsOptimization
? undefined
: {
__next_polyfill__fetch: require.resolve('whatwg-fetch'),
},
{
unfetch$: stubWindowFetch,
'isomorphic-unfetch$': stubWindowFetch,
Expand All @@ -84,13 +75,6 @@ function getOptimizedAliases(
'whatwg-fetch.js'
),
},
polyfillsOptimization
? undefined
: {
// Polyfill: Object.assign
__next_polyfill__object_assign: require.resolve('object-assign'),
'@babel/runtime-corejs2/core-js/object/assign': stubObjectAssign,
},
{
'object-assign$': stubObjectAssign,

Expand Down Expand Up @@ -168,7 +152,6 @@ export default async function getBaseWebpackConfig(
babelPresetPlugins,
hasModern: !!config.experimental.modern,
development: dev,
polyfillsOptimization: !!config.experimental.polyfillsOptimization,
},
},
// Backwards compat
Expand Down Expand Up @@ -215,9 +198,7 @@ export default async function getBaseWebpackConfig(
),
[CLIENT_STATIC_FILES_RUNTIME_POLYFILLS]: path.join(
NEXT_PROJECT_ROOT_DIST_CLIENT,
config.experimental.polyfillsOptimization
? 'polyfills-nomodule.js'
: 'polyfills.js'
'polyfills.js'
),
} as ClientEntries)
: undefined
Expand Down Expand Up @@ -267,17 +248,7 @@ export default async function getBaseWebpackConfig(
next: NEXT_PROJECT_ROOT,
[PAGES_DIR_ALIAS]: pagesDir,
[DOT_NEXT_ALIAS]: distDir,
...getOptimizedAliases(
isServer,
!!config.experimental.polyfillsOptimization
),

// Temporary to allow runtime-corejs2 to be stubbed in experimental polyfillsOptimization
...(config.experimental.polyfillsOptimization
? {
'@babel/runtime-corejs2': '@babel/runtime',
}
: undefined),
...getOptimizedAliases(isServer),
},
mainFields: isServer ? ['main', 'module'] : ['browser', 'module', 'main'],
plugins: [PnpWebpackPlugin],
Expand Down Expand Up @@ -528,11 +499,7 @@ export default async function getBaseWebpackConfig(
!res.match(/next[/\\]dist[/\\]next-server[/\\]/) &&
(res.match(/[/\\]next[/\\]dist[/\\]/) ||
// This is the @babel/plugin-transform-runtime "helpers: true" option
res.match(/node_modules[/\\]@babel[/\\]runtime[/\\]/) ||
(!config.experimental.polyfillsOptimization &&
res.match(
/node_modules[/\\]@babel[/\\]runtime-corejs2[/\\]/
)))
res.match(/node_modules[/\\]@babel[/\\]runtime[/\\]/))
) {
return callback()
}
Expand Down Expand Up @@ -728,9 +695,6 @@ export default async function getBaseWebpackConfig(
'process.env.__NEXT_MODERN_BUILD': JSON.stringify(
config.experimental.modern && !dev
),
'process.env.__NEXT_POLYFILLS_OPTIMIZATION': JSON.stringify(
!!config.experimental.polyfillsOptimization
),
'process.env.__NEXT_GRANULAR_CHUNKS': JSON.stringify(
config.experimental.granularChunks && !dev
),
Expand Down
6 changes: 1 addition & 5 deletions packages/next/build/webpack/loaders/next-babel-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ module.exports = babelLoader.custom(babel => {
hasModern: opts.hasModern,
babelPresetPlugins: opts.babelPresetPlugins,
development: opts.development,
polyfillsOptimization: opts.polyfillsOptimization,
}
const filename = join(opts.cwd, 'noop.js')
const loader = Object.assign(
Expand All @@ -72,7 +71,7 @@ module.exports = babelLoader.custom(babel => {
(opts.isServer ? '-server' : '') +
(opts.isModern ? '-modern' : '') +
(opts.hasModern ? '-has-modern' : '') +
(opts.polyfillsOptimization ? '-new-polyfills' : '') +
'-new-polyfills' +
(opts.development ? '-development' : '-production') +
JSON.stringify(
babel.loadPartialConfig({
Expand All @@ -95,7 +94,6 @@ module.exports = babelLoader.custom(babel => {
delete loader.hasModern
delete loader.pagesDir
delete loader.babelPresetPlugins
delete loader.polyfillsOptimization
delete loader.development
return { loader, custom }
},
Expand All @@ -110,7 +108,6 @@ module.exports = babelLoader.custom(babel => {
pagesDir,
babelPresetPlugins,
development,
polyfillsOptimization,
},
}
) {
Expand All @@ -134,7 +131,6 @@ module.exports = babelLoader.custom(babel => {

options.caller.isServer = isServer
options.caller.isModern = isModern
options.caller.polyfillsOptimization = polyfillsOptimization
options.caller.isDev = development

options.plugins = options.plugins || []
Expand Down
17 changes: 3 additions & 14 deletions packages/next/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,9 @@ import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic'

/// <reference types="react-dom/experimental" />

if (process.env.__NEXT_POLYFILLS_OPTIMIZATION) {
if (!('finally' in Promise.prototype)) {
// eslint-disable-next-line no-extend-native
Promise.prototype.finally = require('finally-polyfill')
}
} else {
// Polyfill Promise globally
// This is needed because Webpack's dynamic loading(common chunks) code
// depends on Promise.
// So, we need to polyfill it.
// See: https://webpack.js.org/guides/code-splitting/#dynamic-imports
if (!self.Promise) {
self.Promise = require('@babel/runtime-corejs2/core-js/promise')
}
if (!('finally' in Promise.prototype)) {
// eslint-disable-next-line no-extend-native
Promise.prototype.finally = require('finally-polyfill')
}

const data = JSON.parse(document.getElementById('__NEXT_DATA__').textContent)
Expand Down
10 changes: 9 additions & 1 deletion packages/next/client/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,15 @@ class Link extends Component<LinkProps> {
if (!this.p || typeof window === 'undefined') return
// Prefetch the JSON page if asked (only in the client)
const [href, asPath] = this.getPaths()
Router.prefetch(href, asPath, options)
// We need to handle a prefetch error here since we may be
// loading with priority which can reject but we don't
// want to force navigation since this is only a prefetch
Router.prefetch(href, asPath, options).catch(err => {
if (process.env.NODE_ENV !== 'production') {
// rethrow to show invalid URL errors
throw err
}
})
prefetched[href] = true
}

Expand Down
1 change: 0 additions & 1 deletion packages/next/client/polyfills-nomodule.js

This file was deleted.

4 changes: 1 addition & 3 deletions packages/next/client/polyfills.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import '__next_polyfill__fetch'
import 'url-polyfill'
Object.assign = require('__next_polyfill__object_assign')
import '@next/polyfill-nomodule'
4 changes: 2 additions & 2 deletions packages/next/next-server/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const defaultConfig: { [key: string]: any } = {
(os.cpus() || { length: 1 }).length) - 1
),
css: true,
scss: false,
scss: true,
documentMiddleware: false,
granularChunks: true,
modern: false,
Expand All @@ -53,7 +53,7 @@ const defaultConfig: { [key: string]: any } = {
workerThreads: false,
basePath: '',
static404: true,
pages404: false,
pages404: true,
},
future: {
excludeDefaultMomentLocales: false,
Expand Down
9 changes: 3 additions & 6 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "9.2.2",
"version": "9.2.3-canary.1",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -72,9 +72,8 @@
"@babel/preset-react": "7.7.0",
"@babel/preset-typescript": "7.7.2",
"@babel/runtime": "7.7.2",
"@babel/runtime-corejs2": "7.7.2",
"@babel/types": "7.7.4",
"@next/polyfill-nomodule": "9.2.2",
"@next/polyfill-nomodule": "9.2.3-canary.1",
"amphtml-validator": "1.0.23",
"async-retry": "1.2.3",
"async-sema": "3.0.0",
Expand Down Expand Up @@ -117,7 +116,6 @@
"mini-css-extract-plugin": "0.8.0",
"mkdirp": "0.5.1",
"node-fetch": "2.6.0",
"object-assign": "4.1.1",
"ora": "3.4.0",
"path-to-regexp": "6.1.0",
"pnp-webpack-plugin": "1.5.0",
Expand Down Expand Up @@ -148,8 +146,7 @@
"webpack": "4.41.2",
"webpack-dev-middleware": "3.7.0",
"webpack-hot-middleware": "2.25.0",
"webpack-sources": "1.4.3",
"whatwg-fetch": "3.0.0"
"webpack-sources": "1.4.3"
},
"peerDependencies": {
"react": "^16.6.0",
Expand Down
5 changes: 0 additions & 5 deletions packages/next/taskfile-babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ module.exports = function(task) {
const output = transform(file.data, options)
const ext = extname(file.base)

output.code = output.code.replace(
/@babel\/runtime\//g,
'@babel/runtime-corejs2/'
)

// Replace `.ts|.tsx` with `.js` in files with an extension
if (ext) {
const extRegex = new RegExp(ext.replace('.', '\\.') + '$', 'i')
Expand Down
3 changes: 0 additions & 3 deletions test/integration/bundle-size-profiling/next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module.exports = {
experimental: {
polyfillsOptimization: true,
},
webpack(config, options) {
if (!options.isServer) {
config.profile = true
Expand Down
9 changes: 1 addition & 8 deletions test/integration/modern-mode/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,7 @@ describe('Modern Mode', () => {
it('should generate client side modern and legacy build files', async () => {
const buildId = readFileSync(join(appDir, '.next/BUILD_ID'), 'utf8')

const expectedFiles = [
'index',
'_app',
'_error',
'main',
'webpack',
'commons',
]
const expectedFiles = ['index', '_app', '_error', 'main', 'webpack']
const buildFiles = [
...readdirSync(join(appDir, '.next/static', buildId, 'pages')),
...readdirSync(join(appDir, '.next/static/runtime')).map(
Expand Down
6 changes: 1 addition & 5 deletions test/integration/polyfilling-minimal/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
polyfillsOptimization: true,
},
}
module.exports = {}
9 changes: 9 additions & 0 deletions test/integration/preload-viewport/pages/invalid-prefetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link'

export default () => (
<>
<Link href="/something-invalid-oops">
<a id="invalid-link">I'm broken...</a>
</Link>
</>
)
Loading

0 comments on commit 9f2ec82

Please sign in to comment.