From c21cbdf8997db636100f578cd70f838f8b95b407 Mon Sep 17 00:00:00 2001 From: Rahul Gaba Date: Wed, 1 Sep 2021 01:53:21 +0530 Subject: [PATCH 1/4] Fix for `next-script-for-ga` ESLint rule crashing when a method is used in dangerouslySetInnerHTML (#28675) Fixes #28635 ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [x] Errors have helpful link attached, see `contributing.md` --- .../lib/rules/next-script-for-ga.js | 4 +-- .../next-script-for-ga.test.ts | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin-next/lib/rules/next-script-for-ga.js b/packages/eslint-plugin-next/lib/rules/next-script-for-ga.js index 09385460dcc8f..8fe6f19189ade 100644 --- a/packages/eslint-plugin-next/lib/rules/next-script-for-ga.js +++ b/packages/eslint-plugin-next/lib/rules/next-script-for-ga.js @@ -52,8 +52,8 @@ module.exports = { // https://developers.google.com/analytics/devguides/collection/analyticsjs#the_google_analytics_tag // https://developers.google.com/tag-manager/quickstart if ( - attributes.has('dangerouslySetInnerHTML') && - attributes.value('dangerouslySetInnerHTML')[0] + attributes.value('dangerouslySetInnerHTML') && + attributes.value('dangerouslySetInnerHTML').length > 0 ) { const htmlContent = attributes.value('dangerouslySetInnerHTML')[0].value.quasis && diff --git a/test/unit/eslint-plugin-next/next-script-for-ga.test.ts b/test/unit/eslint-plugin-next/next-script-for-ga.test.ts index 8200e4aab5edf..19fdde7b0c421 100644 --- a/test/unit/eslint-plugin-next/next-script-for-ga.test.ts +++ b/test/unit/eslint-plugin-next/next-script-for-ga.test.ts @@ -207,5 +207,35 @@ ruleTester.run('sync-scripts', rule, { }, ], }, + { + code: ` + export class Blah extends Head { + createGoogleAnalyticsMarkup() { + return { + __html: \` + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', 'UA-148481588-2');\`, + }; + } + + render() { + return ( +
+

Hello title

+ +
+ ); + } + }`, + errors: [ + { + message: ERROR_MSG, + type: 'JSXOpeningElement', + }, + ], + }, ], }) From c1a97e557b7fad7a87907a56d10f018401154edc Mon Sep 17 00:00:00 2001 From: "jj@jjsweb.site" Date: Tue, 31 Aug 2021 16:11:16 -0500 Subject: [PATCH 2/4] v11.1.3-canary.0 --- 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 a0249a3ed58d4..b162a5c2de701 100644 --- a/lerna.json +++ b/lerna.json @@ -17,5 +17,5 @@ "registry": "https://registry.npmjs.org/" } }, - "version": "11.1.2" + "version": "11.1.3-canary.0" } diff --git a/packages/create-next-app/package.json b/packages/create-next-app/package.json index 421ca033ebba2..51243ea0894f0 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.2", + "version": "11.1.3-canary.0", "keywords": [ "react", "next", diff --git a/packages/eslint-config-next/package.json b/packages/eslint-config-next/package.json index 2f0190611d636..ba291213ad54f 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.2", + "version": "11.1.3-canary.0", "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.2", + "@next/eslint-plugin-next": "11.1.3-canary.0", "@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 8c27193e930ce..5aab6afca0b7b 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.2", + "version": "11.1.3-canary.0", "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 0139279ff26bf..4544abe7c6b26 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.2", + "version": "11.1.3-canary.0", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-codemod/package.json b/packages/next-codemod/package.json index c7e4c3c1b6ec8..528d0a062a1b5 100644 --- a/packages/next-codemod/package.json +++ b/packages/next-codemod/package.json @@ -1,6 +1,6 @@ { "name": "@next/codemod", - "version": "11.1.2", + "version": "11.1.3-canary.0", "license": "MIT", "dependencies": { "chalk": "4.1.0", diff --git a/packages/next-env/package.json b/packages/next-env/package.json index 4ee1ab52d5c23..63000ac7794b1 100644 --- a/packages/next-env/package.json +++ b/packages/next-env/package.json @@ -1,6 +1,6 @@ { "name": "@next/env", - "version": "11.1.2", + "version": "11.1.3-canary.0", "keywords": [ "react", "next", diff --git a/packages/next-mdx/package.json b/packages/next-mdx/package.json index dfaffb7b5b51a..5746a2f1e67a9 100644 --- a/packages/next-mdx/package.json +++ b/packages/next-mdx/package.json @@ -1,6 +1,6 @@ { "name": "@next/mdx", - "version": "11.1.2", + "version": "11.1.3-canary.0", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-plugin-storybook/package.json b/packages/next-plugin-storybook/package.json index 0b88b067b5838..156edd976ee44 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.2", + "version": "11.1.3-canary.0", "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 6cdc212dc50bd..62e3a6b25e121 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.2", + "version": "11.1.3-canary.0", "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 194829ebc6096..4019c9aee91e3 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.2", + "version": "11.1.3-canary.0", "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 43cf8197b78da..ed0cb632ffd54 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -1,6 +1,6 @@ { "name": "next", - "version": "11.1.2", + "version": "11.1.3-canary.0", "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.2", - "@next/polyfill-module": "11.1.2", - "@next/react-dev-overlay": "11.1.2", - "@next/react-refresh-utils": "11.1.2", + "@next/env": "11.1.3-canary.0", + "@next/polyfill-module": "11.1.3-canary.0", + "@next/react-dev-overlay": "11.1.3-canary.0", + "@next/react-refresh-utils": "11.1.3-canary.0", "@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.2", + "@next/polyfill-nomodule": "11.1.3-canary.0", "@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 6a2402e148dcd..5b2d04b362ef6 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.2", + "version": "11.1.3-canary.0", "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 abf739db0b381..9e6ccb0ef7347 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.2", + "version": "11.1.3-canary.0", "description": "An experimental package providing utilities for React Refresh.", "repository": { "url": "vercel/next.js", From 501bfe69695b0e563e88af689105882513c2b370 Mon Sep 17 00:00:00 2001 From: Aleksa Cukovic Date: Tue, 31 Aug 2021 23:18:22 +0200 Subject: [PATCH 3/4] Update docs about exposing env vars to the browser (#28673) Current docs on exposing environment variables to the browser are slightly misleading as they say that variables loaded from `.env.local` are only available in node by default, but this is the case for all environment variables not just those loaded from `.env.local`. ## Documentation - [x] Make sure the linting passes --- docs/basic-features/environment-variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/basic-features/environment-variables.md b/docs/basic-features/environment-variables.md index 7e2ff8e70c3bf..93f65cfdc3a39 100644 --- a/docs/basic-features/environment-variables.md +++ b/docs/basic-features/environment-variables.md @@ -78,7 +78,7 @@ export async function getStaticProps() { ## Exposing Environment Variables to the Browser -By default all environment variables loaded through `.env.local` are only available in the Node.js environment, meaning they won't be exposed to the browser. +By default environment variables are only available in the Node.js environment, meaning they won't be exposed to the browser. In order to expose a variable to the browser you have to prefix the variable with `NEXT_PUBLIC_`. For example: From c1dbc1260922276f62d010e7bccc3ec2c3ccf627 Mon Sep 17 00:00:00 2001 From: Eungyeol <66717787+eungyeole@users.noreply.github.com> Date: Wed, 1 Sep 2021 11:01:55 +0900 Subject: [PATCH 4/4] Do not have the required package error fix (#28662) The following error occurred when I created a project with the typecript template of createp-next-app and did the 'next build'. ```shell It looks like you're trying to use TypeScript but do not have the required package(s) installed. Please install @types/node by running: yarn add --dev @types/node If you are not trying to use TypeScript, please remove the tsconfig.json file from your package root (and any TypeScript files in your pages directory). ``` This issue was resolved by adding @types/node. So I added @types/node to the devDependencies of the create-next-app typecript template. --- packages/create-next-app/create-app.ts | 2 +- test/integration/create-next-app/index.test.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/create-next-app/create-app.ts b/packages/create-next-app/create-app.ts index c06ea76227a54..8d2745db86e03 100644 --- a/packages/create-next-app/create-app.ts +++ b/packages/create-next-app/create-app.ts @@ -226,7 +226,7 @@ export async function createApp({ * TypeScript projects will have type definitions and other devDependencies. */ if (typescript) { - devDependencies.push('typescript', '@types/react') + devDependencies.push('typescript', '@types/react', '@types/node') } /** * Install package.json dependencies if they exist. diff --git a/test/integration/create-next-app/index.test.js b/test/integration/create-next-app/index.test.js index ac3e8bfb82203..47af157d04076 100644 --- a/test/integration/create-next-app/index.test.js +++ b/test/integration/create-next-app/index.test.js @@ -143,6 +143,7 @@ describe('create next app', () => { 'react-dom', ]) expect(Object.keys(pkgJSON.devDependencies)).toEqual([ + '@types/node', '@types/react', 'eslint', 'eslint-config-next',