Skip to content

Commit

Permalink
Merge branch 'canary' into swc-up-3
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Mar 18, 2022
2 parents 5ac8251 + f2fee3d commit ba7b83e
Show file tree
Hide file tree
Showing 66 changed files with 699 additions and 1,017 deletions.
24 changes: 20 additions & 4 deletions .github/workflows/build_test_deploy.yml
Expand Up @@ -208,12 +208,16 @@ jobs:
env:
NEXT_TELEMETRY_DISABLED: 1
NEXT_TEST_JOB: 1
strategy:
fail-fast: false
matrix:
node: [16, 17]
steps:
- name: Setup node
uses: actions/setup-node@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
with:
node-version: 14
node-version: ${{ matrix.node }}

- run: echo ${{needs.build.outputs.docsChange}}

Expand Down Expand Up @@ -258,12 +262,16 @@ jobs:
env:
NEXT_TELEMETRY_DISABLED: 1
NEXT_TEST_JOB: 1
strategy:
fail-fast: false
matrix:
node: [16, 17]
steps:
- name: Setup node
uses: actions/setup-node@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
with:
node-version: 14
node-version: ${{ matrix.node }}

- run: echo ${{needs.build.outputs.docsChange}}

Expand Down Expand Up @@ -308,12 +316,16 @@ jobs:
env:
NEXT_TELEMETRY_DISABLED: 1
NEXT_TEST_JOB: 1
strategy:
fail-fast: false
matrix:
node: [16, 17]
steps:
- name: Setup node
uses: actions/setup-node@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
with:
node-version: 14
node-version: ${{ matrix.node }}

- run: echo ${{needs.build.outputs.docsChange}}

Expand Down Expand Up @@ -348,12 +360,16 @@ jobs:
env:
NEXT_TELEMETRY_DISABLED: 1
NEXT_TEST_JOB: 1
strategy:
fail-fast: false
matrix:
node: [16, 17]
steps:
- name: Setup node
uses: actions/setup-node@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
with:
node-version: 14
node-version: ${{ matrix.node }}

- run: echo ${{needs.build.outputs.docsChange}}

Expand Down
16 changes: 12 additions & 4 deletions docs/api-reference/next/image.md
Expand Up @@ -48,15 +48,23 @@ When using an external URL, you must add it to

### width

The width of the image, in pixels. Must be an integer without a unit.
The `width` property can represent either the _rendered_ width or _original_ width in pixels, depending on the [`layout`](#layout) and [`sizes`](#sizes) properties.

Required, except for statically imported images, or those with [`layout="fill"`](#layout).
When using `layout="intrinsic"`, `layout="fixed"`, or `layout="raw"` without `sizes`, the `width` property represents the _rendered_ width in pixels, so it will affect how large the image appears.

When using `layout="responsive"`, `layout="fill"`, or `layout="raw"` with `sizes`, the `width` property represents the _original_ width in pixels, so it will only affect the aspect ratio.

The `width` property is required, except for [statically imported images](#local-images), or those with `layout="fill"`.

### height

The height of the image, in pixels. Must be an integer without a unit.
The `height` property can represent either the _rendered_ height or _original_ height in pixels, depending on the [`layout`](#layout) and [`sizes`](#sizes) properties.

When using `layout="intrinsic"`, `layout="fixed"`, or `layout="raw"` without `sizes`, the `height` property represents the _rendered_ height in pixels, so it will affect how large the image appears.

When using `layout="responsive"`, `layout="fill"`, or `layout="raw"` with `sizes`, the `height` property represents the _original_ height in pixels, so it will only affect the aspect ratio.

Required, except for statically imported images, or those with [`layout="fill"`](#layout).
The `height` property is required, except for [statically imported images](#local-images), or those with `layout="fill"`.

## Optional Props

Expand Down
4 changes: 2 additions & 2 deletions docs/basic-features/image-optimization.md
Expand Up @@ -150,8 +150,8 @@ One of the ways that images most commonly hurt performance is through _layout sh
Because `next/image` is designed to guarantee good performance results, it cannot be used in a way that will contribute to layout shift, and **must** be sized in one of three ways:

1. Automatically, using a [static import](#local-images)
2. Explicitly, by including a `height` **and** `width` property
3. Implicitly, by using `layout="fill"` which causes the image to expand to fill its parent element.
2. Explicitly, by including a [`width`](/docs/api-reference/next/image.md#width) and [`height`](/docs/api-reference/next/image.md#height) property
3. Implicitly, by using [`layout="fill"`](/docs/api-reference/next/image.md#layout) which causes the image to expand to fill its parent element.

> ### What if I don't know the size of my images?
>
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.13"
"version": "12.1.1-canary.14"
}
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.13",
"version": "12.1.1-canary.14",
"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.13",
"version": "12.1.1-canary.14",
"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.13",
"@next/eslint-plugin-next": "12.1.1-canary.14",
"@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.13",
"version": "12.1.1-canary.14",
"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.13",
"version": "12.1.1-canary.14",
"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.13",
"version": "12.1.1-canary.14",
"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.13",
"version": "12.1.1-canary.14",
"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.13",
"version": "12.1.1-canary.14",
"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.13",
"version": "12.1.1-canary.14",
"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.13",
"version": "12.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",
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.13",
"version": "12.1.1-canary.14",
"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.13",
"version": "12.1.1-canary.14",
"private": true,
"scripts": {
"build-native": "napi build --platform --cargo-name next_swc_napi native",
Expand Down
3 changes: 3 additions & 0 deletions packages/next/build/entries.ts
Expand Up @@ -187,6 +187,9 @@ export async function getPageRuntime(
if (!pageRuntime) {
if (isRuntimeRequired) {
pageRuntime = globalRuntimeFallback
} else {
// @TODO: Remove this branch to fully implement the RFC.
pageRuntime = globalRuntimeFallback
}
}

Expand Down
35 changes: 10 additions & 25 deletions packages/next/build/index.ts
Expand Up @@ -76,11 +76,7 @@ import {
} from '../telemetry/events'
import { Telemetry } from '../telemetry/storage'
import { CompilerResult, runCompiler } from './compiler'
import {
createEntrypoints,
createPagesMapping,
getPageRuntime,
} from './entries'
import { createEntrypoints, createPagesMapping } from './entries'
import { generateBuildId } from './generate-build-id'
import { isWriteable } from './is-writeable'
import * as Log from './output/log'
Expand Down Expand Up @@ -157,10 +153,11 @@ export default async function build(
setGlobal('phase', PHASE_PRODUCTION_BUILD)
setGlobal('distDir', distDir)

// We enable concurrent features (Fizz-related rendering architecture) when
// using React 18 or experimental.
// Currently, when the runtime option is set (either `nodejs` or `edge`),
// we enable concurrent features (Fizz-related rendering architecture).
const runtime = config.experimental.runtime
const hasReactRoot = shouldUseReactRoot()
const hasConcurrentFeatures = hasReactRoot
const hasConcurrentFeatures = !!runtime

const hasServerComponents =
hasReactRoot && !!config.experimental.serverComponents
Expand Down Expand Up @@ -625,7 +622,6 @@ export default async function build(
entrypoints: entrypoints.client,
rewrites,
runWebpackSpan,
hasReactRoot,
}),
getBaseWebpackConfig(dir, {
buildId,
Expand All @@ -637,7 +633,6 @@ export default async function build(
entrypoints: entrypoints.server,
rewrites,
runWebpackSpan,
hasReactRoot,
}),
hasReactRoot
? getBaseWebpackConfig(dir, {
Expand All @@ -651,7 +646,6 @@ export default async function build(
entrypoints: entrypoints.edgeServer,
rewrites,
runWebpackSpan,
hasReactRoot,
})
: null,
])
Expand Down Expand Up @@ -960,22 +954,10 @@ export default async function build(
let ssgPageRoutes: string[] | null = null
let isMiddlewareRoute = !!page.match(MIDDLEWARE_ROUTE)

const pagePath = pagePaths.find((_path) =>
_path.startsWith(actualPage + '.')
)
const pageRuntime =
hasConcurrentFeatures && pagePath
? await getPageRuntime(
join(pagesDir, pagePath),
config.experimental.runtime
)
: null

if (
!isMiddlewareRoute &&
!isReservedPage(page) &&
// We currently don't support staic optimization in the Edge runtime.
pageRuntime !== 'edge'
!hasConcurrentFeatures
) {
try {
let isPageStaticSpan =
Expand Down Expand Up @@ -1501,7 +1483,10 @@ export default async function build(

const combinedPages = [...staticPages, ...ssgPages]

if (combinedPages.length > 0 || useStatic404 || useDefaultStatic500) {
if (
!hasConcurrentFeatures &&
(combinedPages.length > 0 || useStatic404 || useDefaultStatic500)
) {
const staticGenerationSpan = nextBuildSpan.traceChild('static-generation')
await staticGenerationSpan.traceAsyncFn(async () => {
detectConflictingPaths(
Expand Down
13 changes: 6 additions & 7 deletions packages/next/build/webpack-config.ts
Expand Up @@ -48,6 +48,7 @@ import type { Span } from '../trace'
import { getRawPageExtensions } from './utils'
import browserslist from 'next/dist/compiled/browserslist'
import loadJsConfig from './load-jsconfig'
import { shouldUseReactRoot } from '../server/config'
import { getMiddlewareSourceMapPlugins } from './webpack/plugins/middleware-source-maps-plugin'

const watchOptions = Object.freeze({
Expand Down Expand Up @@ -309,7 +310,6 @@ export default async function getBaseWebpackConfig(
rewrites,
isDevFallback = false,
runWebpackSpan,
hasReactRoot,
}: {
buildId: string
config: NextConfigComplete
Expand All @@ -323,7 +323,6 @@ export default async function getBaseWebpackConfig(
rewrites: CustomRoutes['rewrites']
isDevFallback?: boolean
runWebpackSpan: Span
hasReactRoot: boolean
}
): Promise<webpack.Configuration> {
const { useTypeScript, jsConfig, resolvedBaseUrl } = await loadJsConfig(
Expand All @@ -336,10 +335,10 @@ export default async function getBaseWebpackConfig(
rewrites.afterFiles.length > 0 ||
rewrites.fallback.length > 0
const hasReactRefresh: boolean = dev && !isServer

const hasReactRoot = shouldUseReactRoot()
const runtime = config.experimental.runtime

// Make sure `reactRoot` is enabled when React 18 or experimental is detected.
// Make sure reactRoot is enabled when react 18 is detected
if (hasReactRoot) {
config.experimental.reactRoot = true
}
Expand All @@ -354,14 +353,14 @@ export default async function getBaseWebpackConfig(
'`experimental.runtime` requires `experimental.reactRoot` to be enabled along with React 18.'
)
}
if (config.experimental.serverComponents && !hasReactRoot) {
if (config.experimental.serverComponents && !runtime) {
throw new Error(
'`experimental.serverComponents` requires React 18 to be installed.'
'`experimental.runtime` is required to be set along with `experimental.serverComponents`.'
)
}

const targetWeb = isEdgeRuntime || !isServer
const hasConcurrentFeatures = hasReactRoot
const hasConcurrentFeatures = !!runtime && hasReactRoot
const hasServerComponents =
hasConcurrentFeatures && !!config.experimental.serverComponents
const disableOptimizedLoading = hasConcurrentFeatures
Expand Down

0 comments on commit ba7b83e

Please sign in to comment.