Skip to content

Commit

Permalink
Merge branch 'canary' into fix-issue-35286
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Mar 22, 2022
2 parents 7e490bc + a2accb2 commit c85db73
Show file tree
Hide file tree
Showing 27 changed files with 146 additions and 61 deletions.
2 changes: 1 addition & 1 deletion docs/advanced-features/react-18/server-components.md
Expand Up @@ -7,7 +7,7 @@ Server Components allow us to render React components on the server. This is fun
To use React Server Components, ensure you have React 18 installed:

```jsx
npm install next@latest react@rc react-dom@rc
npm install next@canary react@rc react-dom@rc
```

Then, update your `next.config.js`:
Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/data-fetching/get-server-side-props.md
Expand Up @@ -21,7 +21,7 @@ export async function getServerSideProps(context) {
- When you request this page directly, `getServerSideProps` runs at request time, and this page will be pre-rendered with the returned props
- When you request this page on client-side page transitions through [`next/link`](/docs/api-reference/next/link.md) or [`next/router`](/docs/api-reference/next/router.md), Next.js sends an API request to the server, which runs `getServerSideProps`

It then returns `JSON` that contains the result of running `getServerSideProps`, that `JSON` will be used to render the page. All this work will be handled automatically by Next.js, so you don’t need to do anything extra as long as you have `getServerSideProps` defined.
`getServerSideProps` returns JSON which will be used to render the page. All this work will be handled automatically by Next.js, so you don’t need to do anything extra as long as you have `getServerSideProps` defined.

You can use the [next-code-elimination tool](https://next-code-elimination.vercel.app/) to verify what Next.js eliminates from the client-side bundle.

Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/script.md
Expand Up @@ -25,7 +25,7 @@ description: Next.js helps you optimize loading third-party scripts with the bui

</details>

The Next.js Script component, [`next/script`](/docs/api-reference/next/script.md), is an extension of the HTML `<script>` element. It enables developers to set the loading priority of third-party scripts anywhere in their application without needing to append directly to `next/head`, saving developer time while improving loading performance.
The Next.js Script component, [`next/script`](/docs/api-reference/next/script.md), is an extension of the HTML `<script>` element. It enables developers to set the loading priority of third-party scripts anywhere in their application, outside `next/head`, saving developer time while improving loading performance.

```jsx
import Script from 'next/script'
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.1.1-canary.15"
"version": "12.1.1-canary.16"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "12.1.1-canary.15",
"version": "12.1.1-canary.16",
"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": "12.1.1-canary.15",
"version": "12.1.1-canary.16",
"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": "12.1.1-canary.15",
"@next/eslint-plugin-next": "12.1.1-canary.16",
"@rushstack/eslint-patch": "1.0.8",
"@typescript-eslint/parser": "5.10.1",
"eslint-import-resolver-node": "0.3.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "12.1.1-canary.15",
"version": "12.1.1-canary.16",
"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": "12.1.1-canary.15",
"version": "12.1.1-canary.16",
"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": "12.1.1-canary.15",
"version": "12.1.1-canary.16",
"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": "12.1.1-canary.15",
"version": "12.1.1-canary.16",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "12.1.1-canary.15",
"version": "12.1.1-canary.16",
"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": "12.1.1-canary.15",
"version": "12.1.1-canary.16",
"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": "12.1.1-canary.15",
"version": "12.1.1-canary.16",
"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": "12.1.1-canary.15",
"version": "12.1.1-canary.16",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "12.1.1-canary.15",
"version": "12.1.1-canary.16",
"private": true,
"scripts": {
"build-native": "napi build --platform --cargo-name next_swc_napi native",
Expand Down
15 changes: 13 additions & 2 deletions packages/next/build/swc/index.js
Expand Up @@ -76,6 +76,9 @@ async function loadWasm() {
parse(src, options) {
return Promise.resolve(bindings.parse(src.toString(), options))
},
getTargetTriple() {
return undefined
},
}
return wasmBindings
} catch (e) {
Expand Down Expand Up @@ -187,6 +190,8 @@ function loadNative() {
parse(src, options) {
return bindings.parse(src, toBuffer(options ?? {}))
},

getTargetTriple: bindings.getTargetTriple,
}
return nativeBindings
}
Expand Down Expand Up @@ -235,8 +240,14 @@ export async function parse(src, options) {
}

export function getBinaryMetadata() {
let bindings = loadBindingsSync()
let bindings
try {
bindings = loadNative()
} catch (e) {
// Suppress exceptions, this fn allows to fail to load native bindings
}

return {
target: bindings.getTargetTriple(),
target: bindings?.getTargetTriple?.(),
}
}
52 changes: 34 additions & 18 deletions packages/next/build/webpack-config.ts
Expand Up @@ -43,7 +43,11 @@ import { WellKnownErrorsPlugin } from './webpack/plugins/wellknown-errors-plugin
import { regexLikeCss } from './webpack/config/blocks/css'
import { CopyFilePlugin } from './webpack/plugins/copy-file-plugin'
import { FlightManifestPlugin } from './webpack/plugins/flight-manifest-plugin'
import { TelemetryPlugin } from './webpack/plugins/telemetry-plugin'
import {
Feature,
SWC_TARGET_TRIPLE,
TelemetryPlugin,
} from './webpack/plugins/telemetry-plugin'
import type { Span } from '../trace'
import { getRawPageExtensions } from './utils'
import browserslist from 'next/dist/compiled/browserslist'
Expand Down Expand Up @@ -406,6 +410,15 @@ export default async function getBaseWebpackConfig(
const distDir = path.join(dir, config.distDir)

let useSWCLoader = !babelConfigFile
let SWCBinaryTarget: [Feature, boolean] | undefined = undefined
if (useSWCLoader) {
// TODO: we do not collect wasm target yet
const binaryTarget = require('./swc')?.getBinaryMetadata?.()
?.target as SWC_TARGET_TRIPLE
SWCBinaryTarget = binaryTarget
? [`swc/target/${binaryTarget}` as const, true]
: undefined
}

if (!loggedSwcDisabled && !useSWCLoader && babelConfigFile) {
Log.info(
Expand All @@ -419,7 +432,7 @@ export default async function getBaseWebpackConfig(

if (!loggedIgnoredCompilerOptions && !useSWCLoader && config.compiler) {
Log.info(
'`compiler` options in `next.config.js` will be ignored while using Babel https://next.js.org/docs/messages/ignored-compiler-options'
'`compiler` options in `next.config.js` will be ignored while using Babel https://nextjs.org/docs/messages/ignored-compiler-options'
)
loggedIgnoredCompilerOptions = true
}
Expand Down Expand Up @@ -1492,23 +1505,26 @@ export default async function getBaseWebpackConfig(
!dev &&
!isServer &&
new TelemetryPlugin(
new Map([
['swcLoader', useSWCLoader],
['swcMinify', config.swcMinify],
['swcRelay', !!config.compiler?.relay],
['swcStyledComponents', !!config.compiler?.styledComponents],
[
'swcReactRemoveProperties',
!!config.compiler?.reactRemoveProperties,
],
new Map(
[
'swcExperimentalDecorators',
!!jsConfig?.compilerOptions?.experimentalDecorators,
],
['swcRemoveConsole', !!config.compiler?.removeConsole],
['swcImportSource', !!jsConfig?.compilerOptions?.jsxImportSource],
['swcEmotion', !!config.experimental.emotion],
])
['swcLoader', useSWCLoader],
['swcMinify', config.swcMinify],
['swcRelay', !!config.compiler?.relay],
['swcStyledComponents', !!config.compiler?.styledComponents],
[
'swcReactRemoveProperties',
!!config.compiler?.reactRemoveProperties,
],
[
'swcExperimentalDecorators',
!!jsConfig?.compilerOptions?.experimentalDecorators,
],
['swcRemoveConsole', !!config.compiler?.removeConsole],
['swcImportSource', !!jsConfig?.compilerOptions?.jsxImportSource],
['swcEmotion', !!config.experimental.emotion],
SWCBinaryTarget,
].filter<[Feature, boolean]>(Boolean as any)
)
),
].filter(Boolean as any as ExcludesFalse),
}
Expand Down
Expand Up @@ -365,7 +365,9 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance {
// static image imports, CSS imports
file = nodePath.join(this.tracingRoot, file)
const depMod = depModMap.get(file)
const isAsset = reasons.get(file)?.type.includes('asset')
const isAsset = reasons
.get(nodePath.relative(this.tracingRoot, file))
?.type.includes('asset')

return (
!isAsset &&
Expand Down
34 changes: 33 additions & 1 deletion packages/next/build/webpack/plugins/telemetry-plugin.ts
@@ -1,6 +1,24 @@
import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'

type Feature =
/**
* List of target triples next-swc native binary supports.
*/
export type SWC_TARGET_TRIPLE =
| 'x86_64-apple-darwin'
| 'x86_64-unknown-linux-gnu'
| 'x86_64-pc-windows-msvc'
| 'i686-pc-windows-msvc'
| 'aarch64-unknown-linux-gnu'
| 'armv7-unknown-linux-gnueabihf'
| 'aarch64-apple-darwin'
| 'aarch64-linux-android'
| 'arm-linux-androideabi'
| 'x86_64-unknown-freebsd'
| 'x86_64-unknown-linux-musl'
| 'aarch64-unknown-linux-musl'
| 'aarch64-pc-windows-msvc'

export type Feature =
| 'next/image'
| 'next/script'
| 'next/dynamic'
Expand All @@ -13,6 +31,7 @@ type Feature =
| 'swcRemoveConsole'
| 'swcImportSource'
| 'swcEmotion'
| `swc/target/${SWC_TARGET_TRIPLE}`

interface FeatureUsage {
featureName: Feature
Expand Down Expand Up @@ -52,6 +71,19 @@ const BUILD_FEATURES: Array<Feature> = [
'swcRemoveConsole',
'swcImportSource',
'swcEmotion',
'swc/target/x86_64-apple-darwin',
'swc/target/x86_64-unknown-linux-gnu',
'swc/target/x86_64-pc-windows-msvc',
'swc/target/i686-pc-windows-msvc',
'swc/target/aarch64-unknown-linux-gnu',
'swc/target/armv7-unknown-linux-gnueabihf',
'swc/target/aarch64-apple-darwin',
'swc/target/aarch64-linux-android',
'swc/target/arm-linux-androideabi',
'swc/target/x86_64-unknown-freebsd',
'swc/target/x86_64-unknown-linux-musl',
'swc/target/aarch64-unknown-linux-musl',
'swc/target/aarch64-pc-windows-msvc',
]

/**
Expand Down
14 changes: 7 additions & 7 deletions packages/next/package.json
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "12.1.1-canary.15",
"version": "12.1.1-canary.16",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -69,7 +69,7 @@
]
},
"dependencies": {
"@next/env": "12.1.1-canary.15",
"@next/env": "12.1.1-canary.16",
"caniuse-lite": "^1.0.30001283",
"postcss": "8.4.5",
"styled-jsx": "5.0.1",
Expand Down Expand Up @@ -118,11 +118,11 @@
"@hapi/accept": "5.0.2",
"@napi-rs/cli": "2.4.4",
"@napi-rs/triples": "1.1.0",
"@next/polyfill-module": "12.1.1-canary.15",
"@next/polyfill-nomodule": "12.1.1-canary.15",
"@next/react-dev-overlay": "12.1.1-canary.15",
"@next/react-refresh-utils": "12.1.1-canary.15",
"@next/swc": "12.1.1-canary.15",
"@next/polyfill-module": "12.1.1-canary.16",
"@next/polyfill-nomodule": "12.1.1-canary.16",
"@next/react-dev-overlay": "12.1.1-canary.16",
"@next/react-refresh-utils": "12.1.1-canary.16",
"@next/swc": "12.1.1-canary.16",
"@peculiar/webcrypto": "1.3.1",
"@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/next/telemetry/events/build.ts
@@ -1,4 +1,5 @@
import { TelemetryPlugin } from '../../build/webpack/plugins/telemetry-plugin'
import type { SWC_TARGET_TRIPLE } from '../../build/webpack/plugins/telemetry-plugin'

const REGEXP_DIRECTORY_DUNDER =
/[\\/]__[^\\/]+(?<![\\/]__(?:tests|mocks))__[\\/]/i
Expand Down Expand Up @@ -144,6 +145,7 @@ export type EventBuildFeatureUsage = {
| 'swcRemoveConsole'
| 'swcImportSource'
| 'swcEmotion'
| `swc/target/${SWC_TARGET_TRIPLE}`
| 'build-lint'
invocationCount: number
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dev-overlay/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/react-dev-overlay",
"version": "12.1.1-canary.15",
"version": "12.1.1-canary.16",
"description": "A development-only overlay for developing React applications.",
"repository": {
"url": "vercel/next.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-refresh-utils/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/react-refresh-utils",
"version": "12.1.1-canary.15",
"version": "12.1.1-canary.16",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down

0 comments on commit c85db73

Please sign in to comment.