Skip to content

Commit

Permalink
Merge branch 'canary' of https://github.com/aravindputrevu/next.js in…
Browse files Browse the repository at this point in the history
…to canary
  • Loading branch information
aravindputrevu committed Aug 23, 2021
2 parents fe8180d + 861591a commit 798a76c
Show file tree
Hide file tree
Showing 46 changed files with 12,355 additions and 10,123 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build_test_deploy.yml
Expand Up @@ -86,8 +86,6 @@ jobs:
./packages/next/native/next-swc.linux-x64-gnu.node
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
- run: ./scripts/check-pre-compiled.sh
env:
NODE_OPTIONS: '--max_old_space_size=4096'
if: ${{needs.build.outputs.docsChange != 'docs only change'}}

testUnit:
Expand Down
1 change: 1 addition & 0 deletions docs/basic-features/eslint.md
Expand Up @@ -94,6 +94,7 @@ Next.js provides an ESLint plugin, [`eslint-plugin-next`](https://www.npmjs.com/
| ✔️ | [next/no-sync-scripts](https://nextjs.org/docs/messages/no-sync-scripts) | Forbid synchronous scripts |
| ✔️ | [next/no-title-in-document-head](https://nextjs.org/docs/messages/no-title-in-document-head) | Disallow using <title> with Head from next/document |
| ✔️ | [next/no-unwanted-polyfillio](https://nextjs.org/docs/messages/no-unwanted-polyfillio) | Prevent duplicate polyfills from Polyfill.io |
| ✔️ | [next/inline-script-id](https://nextjs.org/docs/messages/inline-script-id) | Enforce id attribute on next/script components with inline content |
| ✔️ | next/no-typos | Ensure no typos were made declaring [Next.js's data fetching function](https://nextjs.org/docs/basic-features/data-fetching) |
| ✔️ | [next/next-script-for-ga](https://nextjs.org/docs/messages/next-script-for-ga) | Use the Script component to defer loading of the script until necessary. |

Expand Down
3 changes: 2 additions & 1 deletion docs/basic-features/script.md
Expand Up @@ -131,13 +131,14 @@ export default function Home() {
```js
import Script from 'next/script'

<Script strategy="lazyOnload">
<Script id="show-banner" strategy="lazyOnload">
{`document.getElementById('banner').removeClass('hidden')`}
</Script>

// or

<Script
id="show-banner"
dangerouslySetInnerHTML={{
__html: `document.getElementById('banner').removeClass('hidden')`
}}
Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/supported-browsers-features.md
Expand Up @@ -20,7 +20,7 @@ In addition, to reduce bundle size, Next.js will only load these polyfills for b

### Server-Side Polyfills

In addition to `fetch()` on the client side, Next.js polyfills `fetch()` in the Node.js environment. You can use `fetch()` on your server code (such as `getStaticProps`) without using polyfills such as `isomorphic-unfetch` or `node-fetch`.
In addition to `fetch()` on the client-side, Next.js polyfills `fetch()` in the Node.js environment. You can use `fetch()` in your server code (such as `getStaticProps`/`getServerSideProps`) without using polyfills such as `isomorphic-unfetch` or `node-fetch`.

### Custom Polyfills

Expand Down
2 changes: 1 addition & 1 deletion docs/migrating/from-create-react-app.md
Expand Up @@ -59,7 +59,7 @@ For more information, see [Migrating from React Router](/docs/migrating/from-rea

Next.js has built-in support for [CSS](/docs/basic-features/built-in-css-support.md), [Sass](/docs/basic-features/built-in-css-support.md#sass-support) and [CSS-in-JS](/docs/basic-features/built-in-css-support.md#css-in-js).

With Create React App, you can import `.css` files directly inside React components. Next.js allows you to do the same, but requires these files to be [CSS Modules](/docs/basic-features/built-in-css-support.md). For global styles, you'll need a [custom `_app.js`](/docs/advanced-features/custom-app.md) to add a [global stylesheet](docs/basic-features/built-in-css-support.md#adding-a-global-stylesheet).
With Create React App, you can import `.css` files directly inside React components. Next.js allows you to do the same, but requires these files to be [CSS Modules](/docs/basic-features/built-in-css-support.md). For global styles, you'll need a [custom `_app.js`](/docs/advanced-features/custom-app.md) to add a [global stylesheet](/docs/basic-features/built-in-css-support.md#adding-a-global-stylesheet).

## Safely Accessing Web APIs

Expand Down
26 changes: 26 additions & 0 deletions errors/inline-script-id.md
@@ -0,0 +1,26 @@
# next/script components with inline content require an `id` attribute

## Why This Error Occurred

`next/script` components with inline content require an `id` attribute to be defined to track and optimize the script.

## Possible Ways to Fix It

Add an `id` attribute to the `next/script` component.

```jsx
import Script from 'next/script'

export default function App({ Component, pageProps }) {
return (
<>
<Script id="my-script">{`console.log('Hello world!');`}</Script>
<Component {...pageProps} />
</>
)
}
```

## Useful links

- [Docs for Next.js Script component](https://nextjs.org/docs/basic-features/script)
4 changes: 4 additions & 0 deletions errors/manifest.json
Expand Up @@ -145,6 +145,10 @@
"title": "incompatible-href-as",
"path": "/errors/incompatible-href-as.md"
},
{
"title": "inline-script-id",
"path": "/errors/inline-script-id.md"
},
{ "title": "install-sass", "path": "/errors/install-sass.md" },
{ "title": "install-sharp", "path": "/errors/install-sharp.md" },
{
Expand Down
10 changes: 5 additions & 5 deletions errors/next-script-for-ga.md
Expand Up @@ -20,8 +20,8 @@ const Home = () => {
<Script
src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"
strategy="lazyOnload"
></Script>
<Script>
/>
<Script id="google-analytics">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){window.dataLayer.push(arguments);}
Expand All @@ -47,7 +47,7 @@ import Script from 'next/script'
const Home = () => {
return (
<div class="container">
<Script>
<Script id="google-analytics">
{`
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
Expand All @@ -73,7 +73,7 @@ import Script from 'next/script'
const Home = () => {
return (
<div class="container">
<Script>
<Script id="google-analytics">
{`
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'GOOGLE_ANALYTICS_ID', 'auto');
Expand All @@ -83,7 +83,7 @@ const Home = () => {
<Script
src="https://www.google-analytics.com/analytics.js"
strategy="lazyOnload"
></Script>
/>
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/with-docker/README.md
Expand Up @@ -22,7 +22,7 @@ You can view your images created with `docker images`.

## Deploying to Google Cloud Run

The `start` script in `package.json` has been modified to accept a `PORT` environment variable (for compatability with Google Cloud Run).
The `start` script in `package.json` has been modified to accept a `PORT` environment variable (for compatibility with Google Cloud Run).

1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/docs/install) so you can use `gcloud` on the command line.
1. Run `gcloud auth login` to log in to your account.
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -17,5 +17,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "11.1.1-canary.11"
"version": "11.1.1-canary.13"
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -50,7 +50,7 @@
"@fullhuman/postcss-purgecss": "1.3.0",
"@mdx-js/loader": "0.18.0",
"@svgr/webpack": "5.5.0",
"@swc/core": "1.2.74",
"@swc/core": "1.2.80",
"@testing-library/react": "11.2.5",
"@types/cheerio": "0.22.16",
"@types/fs-extra": "8.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "11.1.1-canary.11",
"version": "11.1.1-canary.13",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "11.1.1-canary.11",
"version": "11.1.1-canary.13",
"description": "ESLint configuration used by NextJS.",
"main": "index.js",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
"directory": "packages/eslint-config-next"
},
"dependencies": {
"@next/eslint-plugin-next": "11.1.1-canary.11",
"@next/eslint-plugin-next": "11.1.1-canary.13",
"@rushstack/eslint-patch": "^1.0.6",
"@typescript-eslint/parser": "^4.20.0",
"eslint-import-resolver-node": "^0.3.4",
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin-next/lib/index.js
Expand Up @@ -16,6 +16,7 @@ module.exports = {
'no-script-in-head': require('./rules/no-script-in-head'),
'no-typos': require('./rules/no-typos'),
'no-duplicate-head': require('./rules/no-duplicate-head'),
'inline-script-id': require('./rules/inline-script-id'),
'next-script-for-ga': require('./rules/next-script-for-ga'),
},
configs: {
Expand All @@ -39,6 +40,7 @@ module.exports = {
'@next/next/no-script-in-head': 2,
'@next/next/no-typos': 1,
'@next/next/no-duplicate-head': 2,
'@next/next/inline-script-id': 2,
},
},
'core-web-vitals': {
Expand Down
48 changes: 48 additions & 0 deletions packages/eslint-plugin-next/lib/rules/inline-script-id.js
@@ -0,0 +1,48 @@
module.exports = {
meta: {
docs: {
description:
'next/script components with inline content must specify an `id` attribute.',
recommended: true,
},
},
create: function (context) {
let nextScriptImportName = null

return {
ImportDeclaration(node) {
if (node.source.value === 'next/script') {
nextScriptImportName = node.specifiers[0].local.name
}
},
JSXElement(node) {
if (nextScriptImportName == null) return

if (
node.openingElement &&
node.openingElement.name &&
node.openingElement.name.name !== nextScriptImportName
) {
return
}

const attributes = node.openingElement.attributes

if (
node.children.length > 0 ||
attributes.some(
(attribute) => attribute.name.name === 'dangerouslySetInnerHTML'
)
) {
if (!attributes.some((attribute) => attribute.name.name === 'id')) {
context.report({
node,
message:
'next/script components with inline content must specify an `id` attribute. See: https://nextjs.org/docs/messages/inline-script-id',
})
}
}
},
}
},
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "11.1.1-canary.11",
"version": "11.1.1-canary.13",
"description": "ESLint plugin for NextJS.",
"main": "lib/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "11.1.1-canary.11",
"version": "11.1.1-canary.13",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "11.1.1-canary.11",
"version": "11.1.1-canary.13",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "11.1.1-canary.11",
"version": "11.1.1-canary.13",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "11.1.1-canary.11",
"version": "11.1.1-canary.13",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "11.1.1-canary.11",
"version": "11.1.1-canary.13",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "11.1.1-canary.11",
"version": "11.1.1-canary.13",
"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",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "11.1.1-canary.11",
"version": "11.1.1-canary.13",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
4 changes: 3 additions & 1 deletion packages/next/build/webpack-config.ts
Expand Up @@ -742,7 +742,7 @@ export default async function getBaseWebpackConfig(
}

const notExternalModules =
/^(?:private-next-pages\/|next\/(?:dist\/pages\/|(?:app|document|link|image|constants)$)|string-hash$)/
/^(?:private-next-pages\/|next\/(?:dist\/pages\/|(?:app|document|link|image|constants|dynamic)$)|string-hash$)/
if (notExternalModules.test(request)) {
return
}
Expand Down Expand Up @@ -1490,6 +1490,8 @@ export default async function getBaseWebpackConfig(
reactProductionProfiling,
webpack: !!config.webpack,
hasRewrites,
reactRoot: config.experimental.reactRoot,
concurrentFeatures: config.experimental.concurrentFeatures,
})

const cache: any = {
Expand Down

0 comments on commit 798a76c

Please sign in to comment.