Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 10 commits into from Oct 19, 2022
12 changes: 11 additions & 1 deletion docs/basic-features/supported-browsers-features.md
Expand Up @@ -4,7 +4,17 @@ description: Browser support and which JavaScript features are supported by Next

# 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

Expand Down
4 changes: 3 additions & 1 deletion docs/upgrading.md
Expand Up @@ -6,6 +6,8 @@ description: Learn how to upgrade Next.js.

## 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 `swcMinify` configuration property was changed from `false` to `true`. See [Next.js Compiler](/docs/advanced-features/compiler.md) for more info.
Expand All @@ -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 `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

Expand Down
5 changes: 3 additions & 2 deletions packages/next/build/utils.ts
Expand Up @@ -1755,8 +1755,9 @@ export function getSupportedBrowsers(
return browsers
}

// When user does not have browserslist use the default target
// When `experimental.legacyBrowsers: false` the modern default is used
// When the user sets `legacyBrowsers: true`, we pass undefined
// to SWC which is basically ES5 and matches the default behavior
// prior to Next.js 13
return config.experimental.legacyBrowsers
? undefined
: MODERN_BROWSERSLIST_TARGET
Expand Down
4 changes: 1 addition & 3 deletions packages/next/build/webpack-config.ts
Expand Up @@ -698,9 +698,7 @@ export default async function getBaseWebpackConfig(
fileReading: config.experimental.swcFileReading,
nextConfig: config,
jsConfig,
supportedBrowsers: config.experimental.browsersListForSwc
? supportedBrowsers
: undefined,
supportedBrowsers,
swcCacheDir: path.join(dir, config?.distDir ?? '.next', 'cache', 'swc'),
...extraOptions,
},
Expand Down
3 changes: 0 additions & 3 deletions packages/next/server/config-schema.ts
Expand Up @@ -240,9 +240,6 @@ const configSchema = {
},
type: 'object',
},
browsersListForSwc: {
type: 'boolean',
},
cpus: {
type: 'number',
},
Expand Down
5 changes: 1 addition & 4 deletions packages/next/server/config-shared.ts
Expand Up @@ -84,7 +84,6 @@ export interface ExperimentalConfig {
skipTrailingSlashRedirect?: boolean
optimisticClientCache?: boolean
legacyBrowsers?: boolean
browsersListForSwc?: boolean
manualClientBasePath?: boolean
newNextLinkBehavior?: boolean
// custom path to a cache handler to use
Expand Down Expand Up @@ -553,9 +552,7 @@ export const defaultConfig: NextConfig = {
optimisticClientCache: true,
runtime: undefined,
manualClientBasePath: false,
// TODO: change default in next major release (current v12.1.5)
legacyBrowsers: true,
browsersListForSwc: false,
legacyBrowsers: false,
newNextLinkBehavior: true,
cpus: Math.max(
1,
Expand Down
16 changes: 11 additions & 5 deletions packages/next/shared/lib/constants.ts
Expand Up @@ -47,12 +47,18 @@ export const CLIENT_PUBLIC_FILES_PATH = 'public'
export const CLIENT_STATIC_FILES_PATH = 'static'
export const CLIENT_STATIC_FILES_RUNTIME = 'runtime'
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 = [
'chrome 61',
'edge 16',
'firefox 60',
'opera 48',
'safari 11',
'chrome 64',
'edge 79',
'firefox 67',
'opera 51',
'safari 12',
]
export const NEXT_BUILTIN_DOCUMENT = '__NEXT_BUILTIN_DOCUMENT__'
export const NEXT_CLIENT_SSR_ENTRY_SUFFIX = '.__sc_client__'
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/app-dir/app-alias/next.config.js
@@ -1,7 +1,5 @@
module.exports = {
experimental: {
appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
},
}
2 changes: 0 additions & 2 deletions test/e2e/app-dir/app-edge/next.config.js
@@ -1,7 +1,5 @@
module.exports = {
experimental: {
appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
},
}
2 changes: 0 additions & 2 deletions test/e2e/app-dir/app-prefetch/next.config.js
@@ -1,7 +1,5 @@
module.exports = {
experimental: {
appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
},
}
2 changes: 0 additions & 2 deletions test/e2e/app-dir/app-static/next.config.js
@@ -1,8 +1,6 @@
module.exports = {
experimental: {
appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
},
// assetPrefix: '/assets',
rewrites: async () => {
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/app-dir/app/next.config.js
@@ -1,8 +1,6 @@
module.exports = {
experimental: {
appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
sri: {
algorithm: 'sha256',
},
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/app-dir/asset-prefix/next.config.js
@@ -1,8 +1,6 @@
module.exports = {
experimental: {
appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
},
assetPrefix: '/assets',
rewrites() {
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/app-dir/next-font/next.config.js
@@ -1,8 +1,6 @@
module.exports = {
experimental: {
appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
fontLoaders: [
{
loader: '@next/font/local',
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/app-dir/trailingslash/next.config.js
@@ -1,8 +1,6 @@
module.exports = {
experimental: {
appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
},
trailingSlash: true,
}
16 changes: 3 additions & 13 deletions test/e2e/browserslist/browserslist.test.ts
Expand Up @@ -14,11 +14,6 @@ describe('Browserslist', () => {
pages: new FileRef(path.join(appDir, 'pages')),
'.browserslistrc': 'Chrome 73',
},
nextConfig: {
experimental: {
browsersListForSwc: true,
},
},
dependencies: {},
})
})
Expand All @@ -36,14 +31,9 @@ describe('Browserslist', () => {
const src = $(el).attr('src')
if (!src) return
if (src.includes('/index')) {
const code = await fetchViaHTTP(next.url, src).then((res) =>
res.text()
)

const isDev = (global as any).isNextDev
expect(
code.includes(isDev ? 'async ()=>{' : 'async()=>{console.log(')
).toBe(true)
const res = await fetchViaHTTP(next.url, src)
const code = await res.text()
expect(code).toMatch('()=>')
finished = true
}
})
Expand Down
19 changes: 4 additions & 15 deletions test/e2e/browserslist/legacybrowsers-false.test.ts
Expand Up @@ -13,18 +13,12 @@ describe('legacyBrowsers: false', () => {
files: {
pages: new FileRef(path.join(appDir, 'pages')),
},
nextConfig: {
experimental: {
legacyBrowsers: false,
browsersListForSwc: true,
},
},
dependencies: {},
})
})
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 $ = cheerio.load(html)

Expand All @@ -36,14 +30,9 @@ describe('legacyBrowsers: false', () => {
const src = $(el).attr('src')
if (!src) return
if (src.includes('/index')) {
const code = await fetchViaHTTP(next.url, src).then((res) =>
res.text()
)

const isDev = (global as any).isNextDev
expect(
code.includes(isDev ? 'async ()=>{' : 'async()=>{console.log(')
).toBe(true)
const res = await fetchViaHTTP(next.url, src)
const code = await res.text()
expect(code).toMatch('()=>')
finished = true
}
})
Expand Down
15 changes: 5 additions & 10 deletions test/e2e/browserslist/legacybrowsers-true.test.ts
Expand Up @@ -15,15 +15,15 @@ describe('legacyBrowsers: true', () => {
},
nextConfig: {
experimental: {
browsersListForSwc: true,
legacyBrowsers: true,
},
},
dependencies: {},
})
})
afterAll(() => next.destroy())

it('should apply legacyBrowsers: true by default', async () => {
it('should apply legacyBrowsers: true', async () => {
const html = await renderViaHTTP(next.url, '/')
const $ = cheerio.load(html)

Expand All @@ -35,14 +35,9 @@ describe('legacyBrowsers: true', () => {
const src = $(el).attr('src')
if (!src) return
if (src.includes('/index')) {
const code = await fetchViaHTTP(next.url, src).then((res) =>
res.text()
)

const isDev = (global as any).isNextDev
expect(
code.includes(isDev ? 'async ()=>{' : 'async()=>{console.log(')
).toBe(false)
const res = await fetchViaHTTP(next.url, src)
const code = await res.text()
expect(code).not.toMatch('()=>')
finished = true
}
})
Expand Down
Expand Up @@ -84,14 +84,14 @@ describe('Config Experimental Warning', () => {
configFile.write(`
module.exports = {
experimental: {
enableUndici: true,
workerThreads: true,
legacyBrowsers: false,
}
}
`)
const { stderr } = await nextBuild(appDir, [], { stderr: true })
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.'
)
})

Expand Down
4 changes: 2 additions & 2 deletions test/integration/css/test/group-1.test.js
Expand Up @@ -189,7 +189,7 @@ describe('CSS Support', () => {
expect(
cssContent.replace(/\/\*.*?\*\//g, '').trim()
).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
Expand All @@ -210,7 +210,7 @@ describe('CSS Support', () => {
const { version, mappings, sourcesContent } = JSON.parse(cssMapContent)
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(`
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 [
"@media (480px <= width < 768px) {
::placeholder {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/scss/test/group-1.test.js
Expand Up @@ -248,7 +248,7 @@ describe('SCSS Support', () => {
expect(
cssContent.replace(/\/\*.*?\*\//g, '').trim()
).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
Expand All @@ -269,7 +269,7 @@ describe('SCSS Support', () => {
const { version, mappings, sourcesContent } = JSON.parse(cssMapContent)
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(`
Object {
"mappings": "AAEE,4BACE,SAHE,CAEJ,gCACE,SAHE,CAEJ,uBACE,SAHE,CAON,cACE,2CAAA",
"mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA",
"sourcesContent": Array [
"$var: red;
.redText {
Expand Down