From c1a09471ff20363d3446686ab8b234911827d30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 24 Aug 2021 16:08:18 +0200 Subject: [PATCH 1/3] Add missing `typescript` property to `NextConfig` (#28459) This is similar to https://github.com/vercel/next.js/pull/27126 , https://github.com/vercel/next.js/pull/27446 and https://github.com/vercel/next.js/pull/27974 ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [x] Make sure the linting passes --- packages/next/build/index.ts | 4 ++-- packages/next/server/config-shared.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index 061b19351fe1..cf26b1dfcd9f 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -176,7 +176,7 @@ export default async function build( telemetry.record(events) ) - const ignoreTypeScriptErrors = Boolean(config.typescript?.ignoreBuildErrors) + const ignoreTypeScriptErrors = Boolean(config.typescript.ignoreBuildErrors) const typeCheckStart = process.hrtime() const typeCheckingSpinner = createSpinner({ prefixText: `${Log.prefixes.info} ${ @@ -216,7 +216,7 @@ export default async function build( typeCheckingSpinner.stopAndPersist() } - const ignoreESLint = Boolean(config.eslint?.ignoreDuringBuilds) + const ignoreESLint = Boolean(config.eslint.ignoreDuringBuilds) const eslintCacheDir = path.join(cacheDir, 'eslint/') if (!ignoreESLint && runLint) { await nextBuildSpan diff --git a/packages/next/server/config-shared.ts b/packages/next/server/config-shared.ts index 48d577978e2f..d62edf36c62b 100644 --- a/packages/next/server/config-shared.ts +++ b/packages/next/server/config-shared.ts @@ -29,10 +29,16 @@ export interface ESLintConfig { ignoreDuringBuilds?: boolean } +export interface TypeScriptConfig { + /** Do not run TypeScript during production builds (`next build`). */ + ignoreBuildErrors?: boolean +} + export type NextConfig = { [key: string]: any } & { i18n?: I18NConfig | null eslint?: ESLintConfig + typescript?: TypeScriptConfig headers?: () => Promise rewrites?: () => Promise< @@ -139,6 +145,12 @@ export const defaultConfig: NextConfig = { env: {}, webpack: null, webpackDevMiddleware: null, + eslint: { + ignoreDuringBuilds: false, + }, + typescript: { + ignoreBuildErrors: false, + }, distDir: '.next', cleanDistDir: true, assetPrefix: '', From ee462442c815c0358085b0340a005a2b68ae4b77 Mon Sep 17 00:00:00 2001 From: "jj@jjsweb.site" Date: Tue, 24 Aug 2021 09:54:07 -0500 Subject: [PATCH 2/3] v11.1.1-canary.14 --- lerna.json | 2 +- packages/create-next-app/package.json | 2 +- packages/eslint-config-next/package.json | 4 ++-- packages/eslint-plugin-next/package.json | 2 +- packages/next-bundle-analyzer/package.json | 2 +- packages/next-codemod/package.json | 2 +- packages/next-env/package.json | 2 +- packages/next-mdx/package.json | 2 +- packages/next-plugin-storybook/package.json | 2 +- packages/next-polyfill-module/package.json | 2 +- packages/next-polyfill-nomodule/package.json | 2 +- packages/next/package.json | 12 ++++++------ packages/react-dev-overlay/package.json | 2 +- packages/react-refresh-utils/package.json | 2 +- 14 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lerna.json b/lerna.json index 3f04044ac8dd..0d8fbcd8427b 100644 --- a/lerna.json +++ b/lerna.json @@ -17,5 +17,5 @@ "registry": "https://registry.npmjs.org/" } }, - "version": "11.1.1-canary.13" + "version": "11.1.1-canary.14" } diff --git a/packages/create-next-app/package.json b/packages/create-next-app/package.json index 0bbf50b71d70..576175ffdeca 100644 --- a/packages/create-next-app/package.json +++ b/packages/create-next-app/package.json @@ -1,6 +1,6 @@ { "name": "create-next-app", - "version": "11.1.1-canary.13", + "version": "11.1.1-canary.14", "keywords": [ "react", "next", diff --git a/packages/eslint-config-next/package.json b/packages/eslint-config-next/package.json index 3ddc47a29269..0bf87f2b2226 100644 --- a/packages/eslint-config-next/package.json +++ b/packages/eslint-config-next/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-next", - "version": "11.1.1-canary.13", + "version": "11.1.1-canary.14", "description": "ESLint configuration used by NextJS.", "main": "index.js", "license": "MIT", @@ -9,7 +9,7 @@ "directory": "packages/eslint-config-next" }, "dependencies": { - "@next/eslint-plugin-next": "11.1.1-canary.13", + "@next/eslint-plugin-next": "11.1.1-canary.14", "@rushstack/eslint-patch": "^1.0.6", "@typescript-eslint/parser": "^4.20.0", "eslint-import-resolver-node": "^0.3.4", diff --git a/packages/eslint-plugin-next/package.json b/packages/eslint-plugin-next/package.json index 7387076b5f59..f7e31c64a34b 100644 --- a/packages/eslint-plugin-next/package.json +++ b/packages/eslint-plugin-next/package.json @@ -1,6 +1,6 @@ { "name": "@next/eslint-plugin-next", - "version": "11.1.1-canary.13", + "version": "11.1.1-canary.14", "description": "ESLint plugin for NextJS.", "main": "lib/index.js", "license": "MIT", diff --git a/packages/next-bundle-analyzer/package.json b/packages/next-bundle-analyzer/package.json index 1e7765a95716..afcea6cef2ef 100644 --- a/packages/next-bundle-analyzer/package.json +++ b/packages/next-bundle-analyzer/package.json @@ -1,6 +1,6 @@ { "name": "@next/bundle-analyzer", - "version": "11.1.1-canary.13", + "version": "11.1.1-canary.14", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-codemod/package.json b/packages/next-codemod/package.json index 8d889390c1f4..57b258ed2999 100644 --- a/packages/next-codemod/package.json +++ b/packages/next-codemod/package.json @@ -1,6 +1,6 @@ { "name": "@next/codemod", - "version": "11.1.1-canary.13", + "version": "11.1.1-canary.14", "license": "MIT", "dependencies": { "chalk": "4.1.0", diff --git a/packages/next-env/package.json b/packages/next-env/package.json index 3498aa1d9167..a40e64be8c45 100644 --- a/packages/next-env/package.json +++ b/packages/next-env/package.json @@ -1,6 +1,6 @@ { "name": "@next/env", - "version": "11.1.1-canary.13", + "version": "11.1.1-canary.14", "keywords": [ "react", "next", diff --git a/packages/next-mdx/package.json b/packages/next-mdx/package.json index e99f4c7e6f2b..07b3d75e96d5 100644 --- a/packages/next-mdx/package.json +++ b/packages/next-mdx/package.json @@ -1,6 +1,6 @@ { "name": "@next/mdx", - "version": "11.1.1-canary.13", + "version": "11.1.1-canary.14", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-plugin-storybook/package.json b/packages/next-plugin-storybook/package.json index 9ea931290b2c..48b736978878 100644 --- a/packages/next-plugin-storybook/package.json +++ b/packages/next-plugin-storybook/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-storybook", - "version": "11.1.1-canary.13", + "version": "11.1.1-canary.14", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-storybook" diff --git a/packages/next-polyfill-module/package.json b/packages/next-polyfill-module/package.json index fb583ba3f4ff..c61f66a61ed2 100644 --- a/packages/next-polyfill-module/package.json +++ b/packages/next-polyfill-module/package.json @@ -1,6 +1,6 @@ { "name": "@next/polyfill-module", - "version": "11.1.1-canary.13", + "version": "11.1.1-canary.14", "description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)", "main": "dist/polyfill-module.js", "license": "MIT", diff --git a/packages/next-polyfill-nomodule/package.json b/packages/next-polyfill-nomodule/package.json index e9737db02291..b75be468a787 100644 --- a/packages/next-polyfill-nomodule/package.json +++ b/packages/next-polyfill-nomodule/package.json @@ -1,6 +1,6 @@ { "name": "@next/polyfill-nomodule", - "version": "11.1.1-canary.13", + "version": "11.1.1-canary.14", "description": "A polyfill for non-dead, nomodule browsers.", "main": "dist/polyfill-nomodule.js", "license": "MIT", diff --git a/packages/next/package.json b/packages/next/package.json index 254800426912..7f866b711c7e 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -1,6 +1,6 @@ { "name": "next", - "version": "11.1.1-canary.13", + "version": "11.1.1-canary.14", "description": "The React Framework", "main": "./dist/server/next.js", "license": "MIT", @@ -66,10 +66,10 @@ "dependencies": { "@babel/runtime": "7.15.3", "@hapi/accept": "5.0.2", - "@next/env": "11.1.1-canary.13", - "@next/polyfill-module": "11.1.1-canary.13", - "@next/react-dev-overlay": "11.1.1-canary.13", - "@next/react-refresh-utils": "11.1.1-canary.13", + "@next/env": "11.1.1-canary.14", + "@next/polyfill-module": "11.1.1-canary.14", + "@next/react-dev-overlay": "11.1.1-canary.14", + "@next/react-refresh-utils": "11.1.1-canary.14", "@node-rs/helper": "1.2.1", "assert": "2.0.0", "ast-types": "0.13.2", @@ -154,7 +154,7 @@ "@babel/traverse": "7.15.0", "@babel/types": "7.15.0", "@napi-rs/cli": "1.1.0", - "@next/polyfill-nomodule": "11.1.1-canary.13", + "@next/polyfill-nomodule": "11.1.1-canary.14", "@taskr/clear": "1.1.0", "@taskr/esnext": "1.1.0", "@taskr/watch": "1.1.0", diff --git a/packages/react-dev-overlay/package.json b/packages/react-dev-overlay/package.json index a5d5a097bfe0..a53af7fd39c9 100644 --- a/packages/react-dev-overlay/package.json +++ b/packages/react-dev-overlay/package.json @@ -1,6 +1,6 @@ { "name": "@next/react-dev-overlay", - "version": "11.1.1-canary.13", + "version": "11.1.1-canary.14", "description": "A development-only overlay for developing React applications.", "repository": { "url": "vercel/next.js", diff --git a/packages/react-refresh-utils/package.json b/packages/react-refresh-utils/package.json index 002499bc94c3..c0c0d745dd04 100644 --- a/packages/react-refresh-utils/package.json +++ b/packages/react-refresh-utils/package.json @@ -1,6 +1,6 @@ { "name": "@next/react-refresh-utils", - "version": "11.1.1-canary.13", + "version": "11.1.1-canary.14", "description": "An experimental package providing utilities for React Refresh.", "repository": { "url": "vercel/next.js", From fd1c56e66ab0d9612930efac6cb77985fb91fac7 Mon Sep 17 00:00:00 2001 From: Janicklas Ralph Date: Tue, 24 Aug 2021 09:07:38 -0700 Subject: [PATCH 3/3] next/script fix duplicate scripts (#28428) * Fix #27747 * Fix lint error * Add data attribute to script component * Fix #28036 * Fix tests * Fix tests Co-authored-by: JJ Kasper --- packages/next/client/index.tsx | 4 ++++ packages/next/client/script.tsx | 7 +++++-- packages/next/shared/lib/head-manager-context.ts | 1 + test/integration/script-loader/pages/page3.js | 9 ++++----- test/integration/script-loader/test/index.test.js | 13 ++++++++++++- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/next/client/index.tsx b/packages/next/client/index.tsx index 26a2386dd891..86bdc3f6a275 100644 --- a/packages/next/client/index.tsx +++ b/packages/next/client/index.tsx @@ -156,6 +156,7 @@ window.__NEXT_P = [] const headManager: { mountedInstances: Set updateHead: (head: JSX.Element[]) => void + getIsSsr?: () => boolean } = initHeadManager() const appElement: HTMLElement | null = document.getElementById('__next') @@ -163,6 +164,9 @@ let lastRenderReject: (() => void) | null let webpackHMR: any export let router: Router let CachedApp: AppComponent, onPerfEntry: (metric: any) => void +headManager.getIsSsr = () => { + return router.isSsr +} class Container extends React.Component<{ fn: (err: Error, info?: any) => void diff --git a/packages/next/client/script.tsx b/packages/next/client/script.tsx index bd26a8b85733..302991bf3468 100644 --- a/packages/next/client/script.tsx +++ b/packages/next/client/script.tsx @@ -140,7 +140,7 @@ function Script(props: ScriptProps): JSX.Element | null { } = props // Context is available only during SSR - const { updateScripts, scripts } = useContext(HeadManagerContext) + const { updateScripts, scripts, getIsSsr } = useContext(HeadManagerContext) useEffect(() => { if (strategy === 'afterInteractive') { @@ -161,7 +161,10 @@ function Script(props: ScriptProps): JSX.Element | null { }, ]) updateScripts(scripts) - } else { + } else if (getIsSsr && getIsSsr()) { + // Script has already loaded during SSR + LoadCache.add(restProps.id || src) + } else if (getIsSsr && !getIsSsr()) { loadScript(props) } } diff --git a/packages/next/shared/lib/head-manager-context.ts b/packages/next/shared/lib/head-manager-context.ts index 6a0c85acfbd7..7388a1da7b09 100644 --- a/packages/next/shared/lib/head-manager-context.ts +++ b/packages/next/shared/lib/head-manager-context.ts @@ -5,6 +5,7 @@ export const HeadManagerContext: React.Context<{ mountedInstances?: any updateScripts?: (state: any) => void scripts?: any + getIsSsr?: () => boolean }> = React.createContext({}) if (process.env.NODE_ENV !== 'production') { diff --git a/test/integration/script-loader/pages/page3.js b/test/integration/script-loader/pages/page3.js index 58453214b172..592bd84b16fe 100644 --- a/test/integration/script-loader/pages/page3.js +++ b/test/integration/script-loader/pages/page3.js @@ -4,11 +4,10 @@ const Page = () => { return (