Skip to content

Commit 79669b9

Browse files
authored
Merge branch 'canary' into fix/handle-hash-change-error
2 parents 94bcee0 + 4a86a8f commit 79669b9

File tree

35 files changed

+622
-133
lines changed

35 files changed

+622
-133
lines changed

docs/basic-features/environment-variables.md

+7-19
Original file line numberDiff line numberDiff line change
@@ -152,26 +152,14 @@ export default async () => {
152152
153153
## Environment Variable Load Order
154154
155-
Depending on the environment (as set by `NODE_ENV`), Environment Variables are loaded from the following sources in top-to-bottom order. In all environments, the existing `env` is not overridden by following sources:
155+
Environment variables are looked up in the following places, in order, stopping once the variable is found.
156156
157-
`NODE_ENV=production`
158-
159-
1. `.env.production.local`
160-
1. `.env.local`
161-
1. `.env.production`
162-
1. `.env`
163-
164-
`NODE_ENV=development`
165-
166-
1. `.env.development.local`
167-
1. `.env.local`
168-
1. `.env.development`
157+
1. `process.env`
158+
1. `.env.$(NODE_ENV).local`
159+
1. `.env.local` (Not checked when `NODE_ENV` is `test`.)
160+
1. `.env.$(NODE_ENV)`
169161
1. `.env`
170162
171-
`NODE_ENV=test`
172-
173-
1. `.env.test.local`
174-
1. `.env.test`
175-
1. `.env`
163+
For example, if `NODE_ENV` is `development` and you define a variable in both `.env.development.local` and `.env`, the value in `.env.development.local` will be used.
176164
177-
> **Note:** `.env.local` is not loaded when `NODE_ENV=test`.
165+
> **Note:** The allowed values for `NODE_ENV` are `production`, `development` and `test`.

lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"registry": "https://registry.npmjs.org/"
1717
}
1818
},
19-
"version": "12.1.7-canary.6"
19+
"version": "12.1.7-canary.7"
2020
}

packages/create-next-app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-next-app",
3-
"version": "12.1.7-canary.6",
3+
"version": "12.1.7-canary.7",
44
"keywords": [
55
"react",
66
"next",

packages/eslint-config-next/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-config-next",
3-
"version": "12.1.7-canary.6",
3+
"version": "12.1.7-canary.7",
44
"description": "ESLint configuration used by NextJS.",
55
"main": "index.js",
66
"license": "MIT",
@@ -9,7 +9,7 @@
99
"directory": "packages/eslint-config-next"
1010
},
1111
"dependencies": {
12-
"@next/eslint-plugin-next": "12.1.7-canary.6",
12+
"@next/eslint-plugin-next": "12.1.7-canary.7",
1313
"@rushstack/eslint-patch": "^1.1.3",
1414
"@typescript-eslint/parser": "^5.21.0",
1515
"eslint-import-resolver-node": "^0.3.6",

packages/eslint-plugin-next/lib/rules/no-before-interactive-script-outside-document.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ module.exports = {
3131
(child) => child.name && child.name.name === 'strategy'
3232
)
3333

34-
if (!strategy || strategy?.value?.value !== 'beforeInteractive') {
34+
if (
35+
!strategy ||
36+
!strategy.value ||
37+
strategy.value.value !== 'beforeInteractive'
38+
) {
3539
return
3640
}
3741

packages/eslint-plugin-next/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/eslint-plugin-next",
3-
"version": "12.1.7-canary.6",
3+
"version": "12.1.7-canary.7",
44
"description": "ESLint plugin for NextJS.",
55
"main": "lib/index.js",
66
"license": "MIT",

packages/next-bundle-analyzer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/bundle-analyzer",
3-
"version": "12.1.7-canary.6",
3+
"version": "12.1.7-canary.7",
44
"main": "index.js",
55
"license": "MIT",
66
"repository": {

packages/next-codemod/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/codemod",
3-
"version": "12.1.7-canary.6",
3+
"version": "12.1.7-canary.7",
44
"license": "MIT",
55
"dependencies": {
66
"chalk": "4.1.0",

packages/next-env/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/env",
3-
"version": "12.1.7-canary.6",
3+
"version": "12.1.7-canary.7",
44
"keywords": [
55
"react",
66
"next",

packages/next-mdx/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/mdx",
3-
"version": "12.1.7-canary.6",
3+
"version": "12.1.7-canary.7",
44
"main": "index.js",
55
"license": "MIT",
66
"repository": {

packages/next-plugin-storybook/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/plugin-storybook",
3-
"version": "12.1.7-canary.6",
3+
"version": "12.1.7-canary.7",
44
"repository": {
55
"url": "vercel/next.js",
66
"directory": "packages/next-plugin-storybook"

packages/next-polyfill-module/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/polyfill-module",
3-
"version": "12.1.7-canary.6",
3+
"version": "12.1.7-canary.7",
44
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
55
"main": "dist/polyfill-module.js",
66
"license": "MIT",

packages/next-polyfill-nomodule/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/polyfill-nomodule",
3-
"version": "12.1.7-canary.6",
3+
"version": "12.1.7-canary.7",
44
"description": "A polyfill for non-dead, nomodule browsers.",
55
"main": "dist/polyfill-nomodule.js",
66
"license": "MIT",

packages/next-swc/Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/next-swc/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@next/swc",
3-
"version": "12.1.7-canary.6",
3+
"version": "12.1.7-canary.7",
44
"private": true,
55
"scripts": {
66
"build-native": "napi build --platform --cargo-name next_swc_napi native",

packages/next/build/swc/options.js

+8
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export function getLoaderSWCOptions({
192192
hasReactRefresh,
193193
nextConfig,
194194
jsConfig,
195+
supportedBrowsers,
195196
// This is not passed yet as "paths" resolving is handled by webpack currently.
196197
// resolvedBaseUrl,
197198
}) {
@@ -242,6 +243,13 @@ export function getLoaderSWCOptions({
242243
isServer,
243244
pagesDir,
244245
isPageFile,
246+
...(supportedBrowsers && supportedBrowsers.length > 0
247+
? {
248+
env: {
249+
targets: supportedBrowsers,
250+
},
251+
}
252+
: {}),
245253
}
246254
}
247255
}

packages/next/build/webpack-config.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
REACT_LOADABLE_MANIFEST,
2626
SERVERLESS_DIRECTORY,
2727
SERVER_DIRECTORY,
28+
MODERN_BROWSERSLIST_TARGET,
2829
} from '../shared/lib/constants'
2930
import { execOnce } from '../shared/lib/utils'
3031
import { NextConfigComplete } from '../server/config-shared'
@@ -63,16 +64,31 @@ const watchOptions = Object.freeze({
6364

6465
function getSupportedBrowsers(
6566
dir: string,
66-
isDevelopment: boolean
67+
isDevelopment: boolean,
68+
config: NextConfigComplete
6769
): string[] | undefined {
6870
let browsers: any
6971
try {
70-
browsers = browserslist.loadConfig({
72+
const browsersListConfig = browserslist.loadConfig({
7173
path: dir,
7274
env: isDevelopment ? 'development' : 'production',
7375
})
76+
// Running `browserslist` resolves `extends` and other config features into a list of browsers
77+
if (browsersListConfig && browsersListConfig.length > 0) {
78+
browsers = browserslist(browsersListConfig)
79+
}
7480
} catch {}
75-
return browsers
81+
82+
// When user has browserslist use that target
83+
if (browsers && browsers.length > 0) {
84+
return browsers
85+
}
86+
87+
// When user does not have browserslist use the default target
88+
// When `experimental.legacyBrowsers: false` the modern default is used
89+
return config.experimental.legacyBrowsers
90+
? undefined
91+
: MODERN_BROWSERSLIST_TARGET
7692
}
7793

7894
type ExcludesFalse = <T>(x: T | false) => x is T
@@ -339,7 +355,8 @@ export default async function getBaseWebpackConfig(
339355
dir,
340356
config
341357
)
342-
const supportedBrowsers = await getSupportedBrowsers(dir, dev)
358+
const supportedBrowsers = await getSupportedBrowsers(dir, dev, config)
359+
343360
const hasRewrites =
344361
rewrites.beforeFiles.length > 0 ||
345362
rewrites.afterFiles.length > 0 ||
@@ -466,6 +483,9 @@ export default async function getBaseWebpackConfig(
466483
fileReading: config.experimental.swcFileReading,
467484
nextConfig: config,
468485
jsConfig,
486+
supportedBrowsers: config.experimental.browsersListForSwc
487+
? supportedBrowsers
488+
: undefined,
469489
},
470490
}
471491
: {
@@ -1783,6 +1803,7 @@ export default async function getBaseWebpackConfig(
17831803
relay: config.compiler?.relay,
17841804
emotion: config.experimental?.emotion,
17851805
modularizeImports: config.experimental?.modularizeImports,
1806+
legacyBrowsers: config.experimental?.legacyBrowsers,
17861807
})
17871808

17881809
const cache: any = {

packages/next/build/webpack/loaders/next-swc-loader.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
3636

3737
let loaderOptions = this.getOptions() || {}
3838

39-
const { isServer, pagesDir, hasReactRefresh, nextConfig, jsConfig } =
40-
loaderOptions
39+
const {
40+
isServer,
41+
pagesDir,
42+
hasReactRefresh,
43+
nextConfig,
44+
jsConfig,
45+
supportedBrowsers,
46+
} = loaderOptions
4147
const isPageFile = filename.startsWith(pagesDir)
4248

4349
const swcOptions = getLoaderSWCOptions({
@@ -49,6 +55,7 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
4955
hasReactRefresh,
5056
nextConfig,
5157
jsConfig,
58+
supportedBrowsers,
5259
})
5360

5461
const programmaticOptions = {

packages/next/build/webpack/plugins/middleware-plugin.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -177,22 +177,20 @@ function getCodeAnalizer(params: {
177177

178178
/**
179179
* A noop handler to skip analyzing some cases.
180+
* Order matters: for it to work, it must be registered first
180181
*/
181-
const noop = () =>
182+
const skip = () =>
182183
parser.state.module?.layer === 'middleware' ? true : undefined
183184

184-
hooks.call.for('eval').tap(NAME, handleWrapExpression)
185-
hooks.call.for('global.eval').tap(NAME, handleWrapExpression)
186-
hooks.call.for('Function').tap(NAME, handleWrapExpression)
187-
hooks.call.for('global.Function').tap(NAME, handleWrapExpression)
188-
hooks.new.for('Function').tap(NAME, handleWrapExpression)
189-
hooks.new.for('global.Function').tap(NAME, handleWrapExpression)
190-
hooks.expression.for('eval').tap(NAME, handleExpression)
191-
hooks.expression.for('Function').tap(NAME, handleExpression)
192-
hooks.expression.for('global.eval').tap(NAME, handleExpression)
193-
hooks.expression.for('global.Function').tap(NAME, handleExpression)
194-
hooks.expression.for('Function.prototype').tap(NAME, noop)
195-
hooks.expression.for('global.Function.prototype').tap(NAME, noop)
185+
for (const prefix of ['', 'global.']) {
186+
hooks.expression.for(`${prefix}Function.prototype`).tap(NAME, skip)
187+
hooks.expression.for(`${prefix}Function.bind`).tap(NAME, skip)
188+
hooks.call.for(`${prefix}eval`).tap(NAME, handleWrapExpression)
189+
hooks.call.for(`${prefix}Function`).tap(NAME, handleWrapExpression)
190+
hooks.new.for(`${prefix}Function`).tap(NAME, handleWrapExpression)
191+
hooks.expression.for(`${prefix}eval`).tap(NAME, handleExpression)
192+
hooks.expression.for(`${prefix}Function`).tap(NAME, handleExpression)
193+
}
196194
hooks.callMemberChain.for('process').tap(NAME, handleCallMemberChain)
197195
hooks.expressionMemberChain.for('process').tap(NAME, handleCallMemberChain)
198196
}

0 commit comments

Comments
 (0)