diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 6263f321793c3..5430308bd30ab 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -1086,9 +1086,6 @@ export default async function getBaseWebpackConfig( 'process.env.__NEXT_OPTIMIZE_CSS': JSON.stringify( config.experimental.optimizeCss && !dev ), - 'process.env.__NEXT_SCRIPT_LOADER': JSON.stringify( - !!config.experimental.scriptLoader - ), 'process.env.__NEXT_SCROLL_RESTORATION': JSON.stringify( config.experimental.scrollRestoration ), diff --git a/packages/next/client/index.tsx b/packages/next/client/index.tsx index 948861d1de159..080eae4cbaed6 100644 --- a/packages/next/client/index.tsx +++ b/packages/next/client/index.tsx @@ -141,8 +141,8 @@ if (process.env.__NEXT_I18N_SUPPORT) { } } -if (process.env.__NEXT_SCRIPT_LOADER && data.scriptLoader) { - const { initScriptLoader } = require('./experimental-script') +if (data.scriptLoader) { + const { initScriptLoader } = require('./script') initScriptLoader(data.scriptLoader) } diff --git a/packages/next/client/experimental-script.tsx b/packages/next/client/script.tsx similarity index 98% rename from packages/next/client/experimental-script.tsx rename to packages/next/client/script.tsx index 35ae7adf016c9..992f12a416e2f 100644 --- a/packages/next/client/experimental-script.tsx +++ b/packages/next/client/script.tsx @@ -136,10 +136,6 @@ function Script(props: Props): JSX.Element | null { } }, [props, strategy]) - if (!process.env.__NEXT_SCRIPT_LOADER) { - return null - } - if (strategy === 'beforeInteractive') { if (updateScripts) { scripts.beforeInteractive = (scripts.beforeInteractive || []).concat([ diff --git a/packages/next/experimental-script.d.ts b/packages/next/experimental-script.d.ts deleted file mode 100644 index 7bf25c2a85804..0000000000000 --- a/packages/next/experimental-script.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './dist/client/experimental-script' -export { default } from './dist/client/experimental-script' diff --git a/packages/next/experimental-script.js b/packages/next/experimental-script.js deleted file mode 100644 index 9ba204e606219..0000000000000 --- a/packages/next/experimental-script.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./dist/client/experimental-script') diff --git a/packages/next/next-server/server/config-shared.ts b/packages/next/next-server/server/config-shared.ts index 242a247ec05ef..baaf8c469e1b3 100644 --- a/packages/next/next-server/server/config-shared.ts +++ b/packages/next/next-server/server/config-shared.ts @@ -47,7 +47,6 @@ export type NextConfig = { [key: string]: any } & { optimizeImages?: boolean optimizeCss?: boolean scrollRestoration?: boolean - scriptLoader?: boolean stats?: boolean externalDir?: boolean conformance?: boolean @@ -110,7 +109,6 @@ export const defaultConfig: NextConfig = { optimizeImages: false, optimizeCss: false, scrollRestoration: false, - scriptLoader: false, stats: false, externalDir: false, eslint: false, diff --git a/packages/next/package.json b/packages/next/package.json index cc702f5482ced..e85da6e5dec95 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -28,8 +28,8 @@ "dynamic.d.ts", "error.js", "error.d.ts", - "experimental-script.js", - "experimental-script.d.ts", + "script.js", + "script.d.ts", "head.js", "head.d.ts", "image.js", diff --git a/packages/next/pages/_document.tsx b/packages/next/pages/_document.tsx index 9faa6ebfd7414..19ef353bb41f7 100644 --- a/packages/next/pages/_document.tsx +++ b/packages/next/pages/_document.tsx @@ -17,9 +17,7 @@ import { } from '../next-server/server/get-page-files' import { cleanAmpPath } from '../next-server/server/utils' import { htmlEscapeJsonString } from '../server/htmlescape' -import Script, { - Props as ScriptLoaderProps, -} from '../client/experimental-script' +import Script, { Props as ScriptLoaderProps } from '../client/script' export { DocumentContext, DocumentInitialProps, DocumentProps } @@ -536,9 +534,7 @@ export class Head extends Component< children = this.makeStylesheetInert(children) } - if (process.env.__NEXT_SCRIPT_LOADER) { - children = this.handleDocumentScriptLoaderItems(children) - } + children = this.handleDocumentScriptLoaderItems(children) let hasAmphtmlRel = false let hasCanonicalRel = false diff --git a/packages/next/script.d.ts b/packages/next/script.d.ts new file mode 100644 index 0000000000000..8863afb4c85e0 --- /dev/null +++ b/packages/next/script.d.ts @@ -0,0 +1,2 @@ +export * from './dist/client/script' +export { default } from './dist/client/script' diff --git a/packages/next/script.js b/packages/next/script.js new file mode 100644 index 0000000000000..4e0f885ac60a3 --- /dev/null +++ b/packages/next/script.js @@ -0,0 +1 @@ +module.exports = require('./dist/client/script') diff --git a/test/integration/build-output/test/index.test.js b/test/integration/build-output/test/index.test.js index 8a2571989cb64..b92d80a2c4347 100644 --- a/test/integration/build-output/test/index.test.js +++ b/test/integration/build-output/test/index.test.js @@ -123,16 +123,16 @@ describe('Build Output', () => { ) expect(indexSize.endsWith('B')).toBe(true) - expect(parseFloat(indexFirstLoad)).toBeCloseTo(gz ? 63.3 : 194, 1) + expect(parseFloat(indexFirstLoad)).toBeCloseTo(gz ? 64 : 196, 1) expect(indexFirstLoad.endsWith('kB')).toBe(true) expect(parseFloat(err404Size)).toBeCloseTo(gz ? 3.06 : 8.15, 1) expect(err404Size.endsWith('kB')).toBe(true) - expect(parseFloat(err404FirstLoad)).toBeCloseTo(gz ? 66.1 : 202, 1) + expect(parseFloat(err404FirstLoad)).toBeCloseTo(gz ? 66.8 : 204, 1) expect(err404FirstLoad.endsWith('kB')).toBe(true) - expect(parseFloat(sharedByAll)).toBeCloseTo(gz ? 63 : 194, 1) + expect(parseFloat(sharedByAll)).toBeCloseTo(gz ? 63.7 : 196, 1) expect(sharedByAll.endsWith('kB')).toBe(true) const appSizeValue = _appSize.endsWith('kB') @@ -149,7 +149,7 @@ describe('Build Output', () => { true ) - expect(parseFloat(mainSize)).toBeCloseTo(gz ? 19.4 : 60.6, 1) + expect(parseFloat(mainSize)).toBeCloseTo(gz ? 20.1 : 62.8, 1) expect(mainSize.endsWith('kB')).toBe(true) expect(parseFloat(frameworkSize)).toBeCloseTo(gz ? 42.0 : 130, 1) diff --git a/test/integration/script-loader/next.config.js b/test/integration/script-loader/next.config.js index 6a2fac8adf245..4ba52ba2c8df6 100644 --- a/test/integration/script-loader/next.config.js +++ b/test/integration/script-loader/next.config.js @@ -1,3 +1 @@ -module.exports = { - experimental: { scriptLoader: true }, -} +module.exports = {} diff --git a/test/integration/script-loader/pages/_document.js b/test/integration/script-loader/pages/_document.js index e8ccffdc6f28c..d0b9a63d3a4a1 100644 --- a/test/integration/script-loader/pages/_document.js +++ b/test/integration/script-loader/pages/_document.js @@ -1,7 +1,7 @@ import * as React from 'react' /// @ts-ignore import Document, { Main, NextScript, Head } from 'next/document' -import Script from 'next/experimental-script' +import Script from 'next/script' export default class MyDocument extends Document { constructor(props) { diff --git a/test/integration/script-loader/pages/index.js b/test/integration/script-loader/pages/index.js index ee2115adc0f0f..57949b975166e 100644 --- a/test/integration/script-loader/pages/index.js +++ b/test/integration/script-loader/pages/index.js @@ -1,4 +1,4 @@ -import Script from 'next/experimental-script' +import Script from 'next/script' const Page = () => { return ( diff --git a/test/integration/script-loader/pages/page1.js b/test/integration/script-loader/pages/page1.js index 3e3f27f769b0a..8ef106350652e 100644 --- a/test/integration/script-loader/pages/page1.js +++ b/test/integration/script-loader/pages/page1.js @@ -1,4 +1,4 @@ -import Script from 'next/experimental-script' +import Script from 'next/script' const Page = () => { return ( diff --git a/test/integration/script-loader/pages/page3.js b/test/integration/script-loader/pages/page3.js index 64f7f439d2ca8..8da988ec50779 100644 --- a/test/integration/script-loader/pages/page3.js +++ b/test/integration/script-loader/pages/page3.js @@ -1,4 +1,4 @@ -import Script from 'next/experimental-script' +import Script from 'next/script' const Page = () => { return ( diff --git a/test/integration/script-loader/pages/page4.js b/test/integration/script-loader/pages/page4.js index 1c0c3d0af2bcb..aa1ac29358a1f 100644 --- a/test/integration/script-loader/pages/page4.js +++ b/test/integration/script-loader/pages/page4.js @@ -1,4 +1,4 @@ -import Script from 'next/experimental-script' +import Script from 'next/script' const url = 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js' diff --git a/test/integration/size-limit/test/index.test.js b/test/integration/size-limit/test/index.test.js index 1b9ada4200ebb..a695ff0969d5f 100644 --- a/test/integration/size-limit/test/index.test.js +++ b/test/integration/size-limit/test/index.test.js @@ -85,6 +85,6 @@ describe('Production response size', () => { const delta = responseSizesBytes / 1024 // Expected difference: < 0.5 - expect(delta).toBeCloseTo(286.7, 0) + expect(delta).toBeCloseTo(289.3, 0) }) })