Unverified Commit cff9fc9d authored by Steven's avatar Steven Committed by GitHub

BREAKING CHANGE: Remove `browsersListForSwc` and change default to `legacyBrowsers: false` (#41529)

Remove `browsersListForSwc` since it is enabled by default now, and disable `legacyBrowsers` by default.

This PR also bumps the default browserslist to the following:

- Chrome 64+
- Edge 79+
- Firefox 67+
- Opera 51+
- Safari 12+

See related RFC:
- Closes #33227 
Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
parent 3e2aec5e
...@@ -4,7 +4,17 @@ description: Browser support and which JavaScript features are supported by Next ...@@ -4,7 +4,17 @@ description: Browser support and which JavaScript features are supported by Next
# Supported Browsers and Features # Supported Browsers and Features
Next.js supports **IE11 and all modern browsers** (Edge, Firefox, Chrome, Safari, Opera, et al) with no required configuration. Next.js supports **modern browsers** with zero configuration.
- Chrome 64+
- Edge 79+
- Firefox 67+
- Opera 51+
- Safari 12+
## Browserslist
If you would like to target specific browsers or features, Next.js supports [Browserslist](https://browsersl.ist) configuration.
## Polyfills ## Polyfills
......
...@@ -6,6 +6,8 @@ description: Learn how to upgrade Next.js. ...@@ -6,6 +6,8 @@ description: Learn how to upgrade Next.js.
## Upgrading from 12 to 13 ## Upgrading from 12 to 13
The [Supported Browsers](/docs/basic-features/supported-browsers-features.md) have been changed to drop Internet Explorer and target modern browsers.
The minimum Node.js version has been bumped from 12.22.0 to 14.0.0, since 12.x has reached end-of-life. The minimum Node.js version has been bumped from 12.22.0 to 14.0.0, since 12.x has reached end-of-life.
The `swcMinify` configuration property was changed from `false` to `true`. See [Next.js Compiler](/docs/advanced-features/compiler.md) for more info. The `swcMinify` configuration property was changed from `false` to `true`. See [Next.js Compiler](/docs/advanced-features/compiler.md) for more info.
...@@ -15,7 +17,7 @@ A [codemod is available](/docs/advanced-features/codemods.md#next-image-to-legac ...@@ -15,7 +17,7 @@ A [codemod is available](/docs/advanced-features/codemods.md#next-image-to-legac
The `next/link` child can no longer be `<a>`. Add the `legacyBehavior` prop to use the legacy behavior or remove the `<a>` to upgrade. A [codemod is available](/docs/advanced-features/codemods.md#new-link) to automatically upgrade your code. The `next/link` child can no longer be `<a>`. Add the `legacyBehavior` prop to use the legacy behavior or remove the `<a>` to upgrade. A [codemod is available](/docs/advanced-features/codemods.md#new-link) to automatically upgrade your code.
The `target` configuration option has been removed and superseded by [Output File Tracing](https://nextjs.org/docs/advanced-features/output-file-tracing). The `target` configuration property has been removed and superseded by [Output File Tracing](https://nextjs.org/docs/advanced-features/output-file-tracing).
## Upgrading to 12.2 ## Upgrading to 12.2
......
...@@ -1761,8 +1761,9 @@ export function getSupportedBrowsers( ...@@ -1761,8 +1761,9 @@ export function getSupportedBrowsers(
return browsers return browsers
} }
// When user does not have browserslist use the default target // When the user sets `legacyBrowsers: true`, we pass undefined
// When `experimental.legacyBrowsers: false` the modern default is used // to SWC which is basically ES5 and matches the default behavior
// prior to Next.js 13
return config.experimental.legacyBrowsers return config.experimental.legacyBrowsers
? undefined ? undefined
: MODERN_BROWSERSLIST_TARGET : MODERN_BROWSERSLIST_TARGET
......
...@@ -696,9 +696,7 @@ export default async function getBaseWebpackConfig( ...@@ -696,9 +696,7 @@ export default async function getBaseWebpackConfig(
fileReading: config.experimental.swcFileReading, fileReading: config.experimental.swcFileReading,
nextConfig: config, nextConfig: config,
jsConfig, jsConfig,
supportedBrowsers: config.experimental.browsersListForSwc supportedBrowsers,
? supportedBrowsers
: undefined,
swcCacheDir: path.join(dir, config?.distDir ?? '.next', 'cache', 'swc'), swcCacheDir: path.join(dir, config?.distDir ?? '.next', 'cache', 'swc'),
...extraOptions, ...extraOptions,
}, },
......
...@@ -240,9 +240,6 @@ const configSchema = { ...@@ -240,9 +240,6 @@ const configSchema = {
}, },
type: 'object', type: 'object',
}, },
browsersListForSwc: {
type: 'boolean',
},
cpus: { cpus: {
type: 'number', type: 'number',
}, },
......
...@@ -84,7 +84,6 @@ export interface ExperimentalConfig { ...@@ -84,7 +84,6 @@ export interface ExperimentalConfig {
skipTrailingSlashRedirect?: boolean skipTrailingSlashRedirect?: boolean
optimisticClientCache?: boolean optimisticClientCache?: boolean
legacyBrowsers?: boolean legacyBrowsers?: boolean
browsersListForSwc?: boolean
manualClientBasePath?: boolean manualClientBasePath?: boolean
newNextLinkBehavior?: boolean newNextLinkBehavior?: boolean
// custom path to a cache handler to use // custom path to a cache handler to use
...@@ -553,9 +552,7 @@ export const defaultConfig: NextConfig = { ...@@ -553,9 +552,7 @@ export const defaultConfig: NextConfig = {
optimisticClientCache: true, optimisticClientCache: true,
runtime: undefined, runtime: undefined,
manualClientBasePath: false, manualClientBasePath: false,
// TODO: change default in next major release (current v12.1.5) legacyBrowsers: false,
legacyBrowsers: true,
browsersListForSwc: false,
newNextLinkBehavior: true, newNextLinkBehavior: true,
cpus: Math.max( cpus: Math.max(
1, 1,
......
...@@ -47,12 +47,18 @@ export const CLIENT_PUBLIC_FILES_PATH = 'public' ...@@ -47,12 +47,18 @@ export const CLIENT_PUBLIC_FILES_PATH = 'public'
export const CLIENT_STATIC_FILES_PATH = 'static' export const CLIENT_STATIC_FILES_PATH = 'static'
export const CLIENT_STATIC_FILES_RUNTIME = 'runtime' export const CLIENT_STATIC_FILES_RUNTIME = 'runtime'
export const STRING_LITERAL_DROP_BUNDLE = '__NEXT_DROP_CLIENT_FILE__' export const STRING_LITERAL_DROP_BUNDLE = '__NEXT_DROP_CLIENT_FILE__'
/**
* These are the browser versions that support all of the following:
* static import: https://caniuse.com/es6-module
* dynamic import: https://caniuse.com/es6-module-dynamic-import
* import.meta: https://caniuse.com/mdn-javascript_operators_import_meta
*/
export const MODERN_BROWSERSLIST_TARGET = [ export const MODERN_BROWSERSLIST_TARGET = [
'chrome 61', 'chrome 64',
'edge 16', 'edge 79',
'firefox 60', 'firefox 67',
'opera 48', 'opera 51',
'safari 11', 'safari 12',
] ]
export const NEXT_BUILTIN_DOCUMENT = '__NEXT_BUILTIN_DOCUMENT__' export const NEXT_BUILTIN_DOCUMENT = '__NEXT_BUILTIN_DOCUMENT__'
export const NEXT_CLIENT_SSR_ENTRY_SUFFIX = '.__sc_client__' export const NEXT_CLIENT_SSR_ENTRY_SUFFIX = '.__sc_client__'
......
module.exports = { module.exports = {
experimental: { experimental: {
appDir: true, appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
}, },
} }
module.exports = { module.exports = {
experimental: { experimental: {
appDir: true, appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
}, },
} }
module.exports = { module.exports = {
experimental: { experimental: {
appDir: true, appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
}, },
} }
module.exports = { module.exports = {
experimental: { experimental: {
appDir: true, appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
}, },
// assetPrefix: '/assets', // assetPrefix: '/assets',
rewrites: async () => { rewrites: async () => {
......
module.exports = { module.exports = {
experimental: { experimental: {
appDir: true, appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
sri: { sri: {
algorithm: 'sha256', algorithm: 'sha256',
}, },
......
module.exports = { module.exports = {
experimental: { experimental: {
appDir: true, appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
}, },
assetPrefix: '/assets', assetPrefix: '/assets',
rewrites() { rewrites() {
......
module.exports = { module.exports = {
experimental: { experimental: {
appDir: true, appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
fontLoaders: [ fontLoaders: [
{ {
loader: '@next/font/local', loader: '@next/font/local',
......
module.exports = { module.exports = {
experimental: { experimental: {
appDir: true, appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
}, },
trailingSlash: true, trailingSlash: true,
} }
...@@ -14,11 +14,6 @@ describe('Browserslist', () => { ...@@ -14,11 +14,6 @@ describe('Browserslist', () => {
pages: new FileRef(path.join(appDir, 'pages')), pages: new FileRef(path.join(appDir, 'pages')),
'.browserslistrc': 'Chrome 73', '.browserslistrc': 'Chrome 73',
}, },
nextConfig: {
experimental: {
browsersListForSwc: true,
},
},
dependencies: {}, dependencies: {},
}) })
}) })
...@@ -36,14 +31,9 @@ describe('Browserslist', () => { ...@@ -36,14 +31,9 @@ describe('Browserslist', () => {
const src = $(el).attr('src') const src = $(el).attr('src')
if (!src) return if (!src) return
if (src.includes('/index')) { if (src.includes('/index')) {
const code = await fetchViaHTTP(next.url, src).then((res) => const res = await fetchViaHTTP(next.url, src)
res.text() const code = await res.text()
) expect(code).toMatch('()=>')
const isDev = (global as any).isNextDev
expect(
code.includes(isDev ? 'async ()=>{' : 'async()=>{console.log(')
).toBe(true)
finished = true finished = true
} }
}) })
......
...@@ -13,18 +13,12 @@ describe('legacyBrowsers: false', () => { ...@@ -13,18 +13,12 @@ describe('legacyBrowsers: false', () => {
files: { files: {
pages: new FileRef(path.join(appDir, 'pages')), pages: new FileRef(path.join(appDir, 'pages')),
}, },
nextConfig: {
experimental: {
legacyBrowsers: false,
browsersListForSwc: true,
},
},
dependencies: {}, dependencies: {},
}) })
}) })
afterAll(() => next.destroy()) afterAll(() => next.destroy())
it('should apply with legacyBrowsers: false correctly', async () => { it('should apply legacyBrowsers: false by default', async () => {
const html = await renderViaHTTP(next.url, '/') const html = await renderViaHTTP(next.url, '/')
const $ = cheerio.load(html) const $ = cheerio.load(html)
...@@ -36,14 +30,9 @@ describe('legacyBrowsers: false', () => { ...@@ -36,14 +30,9 @@ describe('legacyBrowsers: false', () => {
const src = $(el).attr('src') const src = $(el).attr('src')
if (!src) return if (!src) return
if (src.includes('/index')) { if (src.includes('/index')) {
const code = await fetchViaHTTP(next.url, src).then((res) => const res = await fetchViaHTTP(next.url, src)
res.text() const code = await res.text()
) expect(code).toMatch('()=>')
const isDev = (global as any).isNextDev
expect(
code.includes(isDev ? 'async ()=>{' : 'async()=>{console.log(')
).toBe(true)
finished = true finished = true
} }
}) })
......
...@@ -15,7 +15,7 @@ describe('legacyBrowsers: true', () => { ...@@ -15,7 +15,7 @@ describe('legacyBrowsers: true', () => {
}, },
nextConfig: { nextConfig: {
experimental: { experimental: {
browsersListForSwc: true, legacyBrowsers: true,
}, },
}, },
dependencies: {}, dependencies: {},
...@@ -23,7 +23,7 @@ describe('legacyBrowsers: true', () => { ...@@ -23,7 +23,7 @@ describe('legacyBrowsers: true', () => {
}) })
afterAll(() => next.destroy()) afterAll(() => next.destroy())
it('should apply legacyBrowsers: true by default', async () => { it('should apply legacyBrowsers: true', async () => {
const html = await renderViaHTTP(next.url, '/') const html = await renderViaHTTP(next.url, '/')
const $ = cheerio.load(html) const $ = cheerio.load(html)
...@@ -35,14 +35,9 @@ describe('legacyBrowsers: true', () => { ...@@ -35,14 +35,9 @@ describe('legacyBrowsers: true', () => {
const src = $(el).attr('src') const src = $(el).attr('src')
if (!src) return if (!src) return
if (src.includes('/index')) { if (src.includes('/index')) {
const code = await fetchViaHTTP(next.url, src).then((res) => const res = await fetchViaHTTP(next.url, src)
res.text() const code = await res.text()
) expect(code).not.toMatch('()=>')
const isDev = (global as any).isNextDev
expect(
code.includes(isDev ? 'async ()=>{' : 'async()=>{console.log(')
).toBe(false)
finished = true finished = true
} }
}) })
......
...@@ -84,14 +84,14 @@ describe('Config Experimental Warning', () => { ...@@ -84,14 +84,14 @@ describe('Config Experimental Warning', () => {
configFile.write(` configFile.write(`
module.exports = { module.exports = {
experimental: { experimental: {
enableUndici: true,
workerThreads: true, workerThreads: true,
legacyBrowsers: false,
} }
} }
`) `)
const { stderr } = await nextBuild(appDir, [], { stderr: true }) const { stderr } = await nextBuild(appDir, [], { stderr: true })
expect(stderr).toMatch( expect(stderr).toMatch(
'You have enabled experimental features (workerThreads, legacyBrowsers) in next.config.js.' 'You have enabled experimental features (enableUndici, workerThreads) in next.config.js.'
) )
}) })
......
...@@ -189,7 +189,7 @@ describe('CSS Support', () => { ...@@ -189,7 +189,7 @@ describe('CSS Support', () => {
expect( expect(
cssContent.replace(/\/\*.*?\*\//g, '').trim() cssContent.replace(/\/\*.*?\*\//g, '').trim()
).toMatchInlineSnapshot( ).toMatchInlineSnapshot(
`"@media (min-width:480px) and (max-width:767px){::-moz-placeholder{color:green}:-ms-input-placeholder{color:green}::placeholder{color:green}}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}.transform-parsing{transform:translate3d(0,0)}.css-grid-shorthand{grid-column:span 2}.g-docs-sidenav .filter::-webkit-input-placeholder{opacity:80%}"` `"@media (min-width:480px) and (max-width:767px){::placeholder{color:green}}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}.transform-parsing{transform:translate3d(0,0)}.css-grid-shorthand{grid-column:span 2}.g-docs-sidenav .filter::-webkit-input-placeholder{opacity:80%}"`
) )
// Contains a source map // Contains a source map
...@@ -210,7 +210,7 @@ describe('CSS Support', () => { ...@@ -210,7 +210,7 @@ describe('CSS Support', () => {
const { version, mappings, sourcesContent } = JSON.parse(cssMapContent) const { version, mappings, sourcesContent } = JSON.parse(cssMapContent)
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(` expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(`
Object { Object {
"mappings": "AAAA,+CACE,mBACE,WACF,CAFA,uBACE,WACF,CAFA,cACE,WACF,CACF,CAEA,cACE,2CACF,CAEA,mBACE,0BACF,CAEA,oBACE,kBACF,CAEA,mDACE,WACF", "mappings": "AAAA,+CACE,cACE,WACF,CACF,CAEA,cACE,2CACF,CAEA,mBACE,0BACF,CAEA,oBACE,kBACF,CAEA,mDACE,WACF",
"sourcesContent": Array [ "sourcesContent": Array [
"@media (480px <= width < 768px) { "@media (480px <= width < 768px) {
::placeholder { ::placeholder {
......
...@@ -248,7 +248,7 @@ describe('SCSS Support', () => { ...@@ -248,7 +248,7 @@ describe('SCSS Support', () => {
expect( expect(
cssContent.replace(/\/\*.*?\*\//g, '').trim() cssContent.replace(/\/\*.*?\*\//g, '').trim()
).toMatchInlineSnapshot( ).toMatchInlineSnapshot(
`".redText ::-moz-placeholder{color:red}.redText :-ms-input-placeholder{color:red}.redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"` `".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"`
) )
// Contains a source map // Contains a source map
...@@ -269,7 +269,7 @@ describe('SCSS Support', () => { ...@@ -269,7 +269,7 @@ describe('SCSS Support', () => {
const { version, mappings, sourcesContent } = JSON.parse(cssMapContent) const { version, mappings, sourcesContent } = JSON.parse(cssMapContent)
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(` expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(`
Object { Object {
"mappings": "AAEE,4BACE,SAHE,CAEJ,gCACE,SAHE,CAEJ,uBACE,SAHE,CAON,cACE,2CAAA", "mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA",
"sourcesContent": Array [ "sourcesContent": Array [
"$var: red; "$var: red;
.redText { .redText {
......
...@@ -2,41 +2,47 @@ import { createNext } from 'e2e-utils' ...@@ -2,41 +2,47 @@ import { createNext } from 'e2e-utils'
import { NextConfig } from 'packages/next' import { NextConfig } from 'packages/next'
import { NextInstance } from 'test/lib/next-modes/base' import { NextInstance } from 'test/lib/next-modes/base'
describe('ES Check default output', () => { describe('ES Check .next output', () => {
let next: NextInstance let next: NextInstance
afterEach(() => next.destroy())
beforeAll(async () => { it('should emit ES2020 with default', async () => {
next = await createNext({ next = await createNext({
files: { files: {
'pages/index.js': 'export default function Page() { return "hello" }', 'pages/index.js': 'export default function Page() { return "hi" }',
}, },
dependencies: { 'es-check': '7.0.0' }, dependencies: { 'es-check': '7.0.1' },
packageJson: { packageJson: {
scripts: { scripts: {
build: 'next build && es-check es5 .next/static/**/*.js', build: 'next build && es-check es2020 .next/static/**/*.js',
}, },
}, },
buildCommand: 'yarn build', buildCommand: 'yarn build',
}) })
})
afterAll(() => next.destroy())
it('should pass for ES5', async () => {
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'info: ES-Check: there were no ES version matching errors! 🎉' 'info: ES-Check: there were no ES version matching errors! 🎉'
) )
}) })
it('should pass for ES5 with SWC minify', async () => { it('should emit ES5 with legacyBrowsers: true', async () => {
await next.stop() const nextConfig: NextConfig = {
await next.deleteFile('.next') experimental: {
await next.patchFile( legacyBrowsers: true,
'next.config.js', },
` }
module.exports = ${JSON.stringify({ swcMinify: true } as NextConfig)} next = await createNext({
` files: {
) 'pages/index.js': 'export default function Page() { return "hi" }',
await next.start() 'next.config.js': `module.exports = ${JSON.stringify(nextConfig)}`,
},
dependencies: { 'es-check': '7.0.1' },
packageJson: {
scripts: {
build: 'next build && es-check es5 .next/static/**/*.js',
},
},
buildCommand: 'yarn build',
})
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'info: ES-Check: there were no ES version matching errors! 🎉' 'info: ES-Check: there were no ES version matching errors! 🎉'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment