Skip to content

Commit

Permalink
Merge branch 'canary' into fix/buffer-unusable-on-edge
Browse files Browse the repository at this point in the history
  • Loading branch information
feugy committed Aug 3, 2022
2 parents e910314 + 213c42f commit dfa8663
Show file tree
Hide file tree
Showing 72 changed files with 2,166 additions and 1,137 deletions.
4 changes: 2 additions & 2 deletions docs/api-reference/next.config.js/rewrites.md
Expand Up @@ -42,15 +42,15 @@ module.exports = {

Rewrites are applied to client-side routing, a `<Link href="/about">` will have the rewrite applied in the above example.

`rewrites` is an async function that expects an array to be returned holding objects with `source` and `destination` properties:
`rewrites` is an async function that expects to return either an array or an object of arrays (see below) holding objects with `source` and `destination` properties:

- `source`: `String` - is the incoming request path pattern.
- `destination`: `String` is the path you want to route to.
- `basePath`: `false` or `undefined` - if false the basePath won't be included when matching, can be used for external rewrites only.
- `locale`: `false` or `undefined` - whether the locale should not be included when matching.
- `has` is an array of [has objects](#header-cookie-and-query-matching) with the `type`, `key` and `value` properties.

Rewrites are applied after checking the filesystem (pages and `/public` files) and before dynamic routes by default. This behavior can be changed by returning an object instead of an array from the `rewrites` function since `v10.1` of Next.js:
When the `rewrites` function returns an array, rewrites are applied after checking the filesystem (pages and `/public` files) and before dynamic routes. When the `rewrites` function returns an object of arrays with a specific shape, this behavior can be changed and more finely controlled, as of `v10.1` of Next.js:

```js
module.exports = {
Expand Down
153 changes: 146 additions & 7 deletions docs/api-reference/next/future/image.md
Expand Up @@ -9,6 +9,7 @@ description: Try the latest Image Optimization with the experimental `next/futur

| Version | Changes |
| --------- | -------------------------------------------- |
| `v12.2.4` | Support for `fill` property added. |
| `v12.2.0` | Experimental `next/future/image` introduced. |

</details>
Expand All @@ -29,23 +30,145 @@ module.exports = {
}
```

## Comparison

Compared to `next/image`, the new `next/future/image` component has the following changes:

- Renders a single `<img>` without `<div>` or `<span>` wrappers
- Adds support for canonical `style` prop
- Removes `layout`, `objectFit`, and `objectPosition` props in favor of `style` or `className`
- Removes `IntersectionObserver` implementation in favor of [native lazy loading](https://caniuse.com/loading-lazy-attr)
- Removes `loader` config in favor of [`loader`](#loader) prop
- Note: there is no `fill` mode so `width` & `height` props are required
- Note: the [`onError`](#onerror) prop might behave differently

The default layout for `next/image` was `intrinsic`, which would shrink the `width` if the image was larger than it's container. Since no styles are automatically applied to `next/future/image`, you'll need to add the following CSS to achieve the same behavior:
## Migration

Although `layout` is not available, you can migrate `next/image` to `next/future/image` using a few props. The following is a comparison of the two components:

<table>
<thead>
<tr>
<th>next/image</th>
<th>next/future/image</th>
</tr>
</thead>
<tbody>

<tr>
<td>

```jsx
import Image from 'next/image'
import img from '../img.png'

function Page() {
return <Image src={img} />
}
```

</td>
<td>

```jsx
import Image from 'next/future/image'
import img from '../img.png'

const css = { maxWidth: '100%', height: 'auto' }
function Page() {
return <Image src={img} style={css} />
}
```

</td>
</tr>

<tr>
<td>

```jsx
import Image from 'next/image'
import img from '../img.png'

function Page() {
return <Image src={img} layout="responsive" />
}
```

</td>
<td>

```jsx
import Image from 'next/future/image'
import img from '../img.png'

const css = { width: '100%', height: 'auto' }
function Page() {
return <Image src={img} sizes="100vw" style={css} />
}
```

</td>
</tr>

<tr>
<td>

```jsx
import Image from 'next/image'
import img from '../img.png'

```css
max-width: 100%;
height: auto;
function Page() {
return <Image src={img} layout="fill" />
}
```

</td>
<td>

```jsx
import Image from 'next/future/image'
import img from '../img.png'

function Page() {
return <Image src={img} sizes="100vw" fill />
}
```

</td>
</tr>

<tr>
<td>

```jsx
import Image from 'next/image'
import img from '../img.png'

function Page() {
return <Image src={img} layout="fixed" />
}
```

</td>
<td>

```jsx
import Image from 'next/future/image'
import img from '../img.png'

function Page() {
return <Image src={img} />
}
```

</td>
</tr>

</tbody>
</table>

You can also use `className` instead of `style`.

## Required Props

The `<Image />` component requires the following properties.
Expand All @@ -64,13 +187,13 @@ When using an external URL, you must add it to [domains](#domains) in `next.conf

The `width` property represents the _rendered_ width in pixels, so it will affect how large the image appears.

Required, except for [statically imported images](/docs/basic-features/image-optimization.md#local-images).
Required, except for [statically imported images](/docs/basic-features/image-optimization.md#local-images) or images with the [`fill` property](#fill).

### height

The `height` property represents the _rendered_ height in pixels, so it will affect how large the image appears.

Required, except for [statically imported images](/docs/basic-features/image-optimization.md#local-images).
Required, except for [statically imported images](/docs/basic-features/image-optimization.md#local-images) or images with the [`fill` property](#fill).

## Optional Props

Expand Down Expand Up @@ -108,6 +231,22 @@ const MyImage = (props) => {
}
```

### fill

A boolean that causes the image to fill the parent element instead of setting [`width`](#width) and [`height`](#height).

The parent element _must_ assign `position: "relative"`, `position: "fixed"`, or `position: "absolute"` style.

By default, the img element will automatically assign `object-fit: "contain"` and `position: "absolute"` styles.

Optionally, `object-fit` can be assigned any other value such as `object-fit: "cover"`. For this to look correct, the `overflow: "hidden"` style should be assigned to the parent element.

See also:

- [position](https://developer.mozilla.org/en-US/docs/Web/CSS/position)
- [object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit)
- [object-position](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position)

### sizes

A string that provides information about how wide the image will be at different breakpoints.
Expand Down
8 changes: 5 additions & 3 deletions examples/with-docker-compose/next-app/dev.Dockerfile
Expand Up @@ -5,9 +5,11 @@ WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
[ -f package-lock.json ] && npm install || \
[ -f pnpm-lock.yaml ] && yarn global add pnpm && pnpm install || \
yarn install
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \
else echo "Lockfile not found." && exit 1; \
fi

COPY src ./src
COPY public ./public
Expand Down
Expand Up @@ -6,7 +6,7 @@ WORKDIR /app
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
# Omit --production flag for TypeScript devDependencies
RUN \
if [ -f yarn.lock ]; then yarn install --frozen-lockfile; \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \
else echo "Lockfile not found." && exit 1; \
Expand Down
4 changes: 2 additions & 2 deletions examples/with-docker-compose/next-app/prod.Dockerfile
Expand Up @@ -7,7 +7,7 @@ WORKDIR /app
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
# Omit --production flag for TypeScript devDependencies
RUN \
if [ -f yarn.lock ]; then yarn install --frozen-lockfile; \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \
else echo "Lockfile not found." && exit 1; \
Expand Down Expand Up @@ -45,7 +45,7 @@ COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.js .
COPY --from=builder /app/package.json .

# Automatically leverage output traces to reduce image size
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
Expand Down
10 changes: 5 additions & 5 deletions examples/with-docker-multi-env/docker/development/Dockerfile
Expand Up @@ -8,10 +8,10 @@ WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile;\
elif [ -f package-lock.json ]; then npm ci;\
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i;\
else echo "Lockfile not found." && exit 1;\
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \
else echo "Lockfile not found." && exit 1; \
fi

# 2. Rebuild the source code only when needed
Expand All @@ -37,7 +37,7 @@ RUN adduser -S nextjs -u 1001
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json

# Automatically leverage output traces to reduce image size
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
Expand Down
Expand Up @@ -38,7 +38,7 @@ RUN adduser -S nextjs -u 1001
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json

# Automatically leverage output traces to reduce image size
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
Expand Down
2 changes: 1 addition & 1 deletion examples/with-docker-multi-env/docker/staging/Dockerfile
Expand Up @@ -38,7 +38,7 @@ RUN adduser -S nextjs -u 1001
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json

# Automatically leverage output traces to reduce image size
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
Expand Down
2 changes: 1 addition & 1 deletion examples/with-docker/Dockerfile
Expand Up @@ -46,7 +46,7 @@ RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json

# Automatically leverage output traces to reduce image size
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
Expand Down
2 changes: 1 addition & 1 deletion examples/with-edgedb/edgedb.toml
@@ -1,2 +1,2 @@
[edgedb]
server-version = "1.2"
server-version = "2"
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.2.4-canary.8"
"version": "12.2.4-canary.9"
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -56,7 +56,7 @@
"@babel/plugin-proposal-object-rest-spread": "7.14.7",
"@babel/preset-flow": "7.14.5",
"@babel/preset-react": "7.14.5",
"@edge-runtime/jest-environment": "1.1.0-beta.23",
"@edge-runtime/jest-environment": "1.1.0-beta.25",
"@fullhuman/postcss-purgecss": "1.3.0",
"@mdx-js/loader": "0.18.0",
"@next/bundle-analyzer": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "12.2.4-canary.8",
"version": "12.2.4-canary.9",
"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.2.4-canary.8",
"version": "12.2.4-canary.9",
"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.2.4-canary.8",
"@next/eslint-plugin-next": "12.2.4-canary.9",
"@rushstack/eslint-patch": "^1.1.3",
"@typescript-eslint/parser": "^5.21.0",
"eslint-import-resolver-node": "^0.3.6",
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.2.4-canary.8",
"version": "12.2.4-canary.9",
"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.2.4-canary.8",
"version": "12.2.4-canary.9",
"main": "index.js",
"types": "index.d.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "12.2.4-canary.8",
"version": "12.2.4-canary.9",
"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.2.4-canary.8",
"version": "12.2.4-canary.9",
"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.2.4-canary.8",
"version": "12.2.4-canary.9",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down

0 comments on commit dfa8663

Please sign in to comment.