Skip to content

Commit 0f22fde

Browse files
authored
Merge branch 'master' into chore/update-advanced-features-custom-server
2 parents f734aee + aa1ed8d commit 0f22fde

File tree

5 files changed

+95
-8
lines changed

5 files changed

+95
-8
lines changed

docs/advanced-features/amp-support/adding-amp-components.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: AMPコミュニティのコンポーネントを追加して、よ
44

55
# AMPコンポーネントの追加
66

7-
AMPコミュニティは、よりインタラクティブなAMPページを作成するのに役立つ [たくさんのコンポーネント](https://amp.dev/documentation/components/) を提供しています。 Next.js はページで使用されるすべてのコンポーネントを自動的にインポートするので、AMPコンポーネントのスクリプトを手動でインポートする必要はありません:
7+
AMP コミュニティは、よりインタラクティブな AMP ページを作成するのに役立つ [たくさんのコンポーネント](https://amp.dev/documentation/components/) を提供しています。 Next.js はページで使用されるすべてのコンポーネントを自動的にインポートするので、AMP コンポーネントのスクリプトを手動でインポートする必要はありません:
88

99
```jsx
1010
export const config = { amp: true };
@@ -49,7 +49,12 @@ function MyAmpPage() {
4949
</Head>
5050

5151
<p>Some time: {date.toJSON()}</p>
52-
<amp-timeago width="0" height="15" datetime={date.toJSON()} layout="responsive">
52+
<amp-timeago
53+
width="0"
54+
height="15"
55+
datetime={date.toJSON()}
56+
layout="responsive"
57+
>
5358
.
5459
</amp-timeago>
5560
</div>

docs/advanced-features/amp-support/amp-in-static-html-export.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Next.js は、HTML ページに AMP ページへのリンクを自動的に挿
2727
<link rel="canonical" href="/about" />
2828
```
2929

30-
[`exportTrailingSlash`](/docs/api-reference/next.config.js/exportPathMap.md#0cf7d6666b394c5d8d08a16a933e86ea) を有効にすると、 `pages/about.js` は以下のようにエクスポートされます:
30+
[`trailingSlash`](/docs/api-reference/next.config.js/trailingSlash.md) を有効にすると、 `pages/about.js` は以下のようにエクスポートされます:
3131

3232
- `out/about/index.html` - HTML ページ
3333
- `out/about.amp/index.html` - AMP ページ

docs/advanced-features/amp-support/amp-validation.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,27 @@ description: AMPページは、開発時やビルド時にNext.jsによって自
77
AMP ページは開発時に [amphtml-validator](https://www.npmjs.com/package/amphtml-validator) によって自動的に検証されます。 エラーや注意事項は Next.js を起動したターミナルに表示されます。
88

99
ページは [静的 HTML のエクスポート](/docs/advanced-features/static-html-export.md) 時にも検証され、エラーや注意事項はターミナルに表示されます。有効ではない AMP のエクスポートによって、AMP のエラーが発生した場合は、ステータスコード `1` で処理を終了します。
10+
11+
### 検証のカスタム
12+
13+
以下のような `next.config.js` によって、AMP ページの検証をカスタマイズできます。
14+
15+
```jsx
16+
module.exports = {
17+
amp: {
18+
validator: './custom_validator.js',
19+
},
20+
}
21+
```
22+
23+
### 検証のスキップ
24+
25+
AMP ページの検証をオフにする場合は、`next.config.js` に以下のコードを追加します。
26+
27+
```jsx
28+
experimental: {
29+
amp: {
30+
skipValidation: true
31+
}
32+
}
33+
```

docs/advanced-features/automatic-static-optimization.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,30 @@ description: Next.js は可能であれば静的な HTML へとアプリケー
2121

2222
プリレンダリング中は、この段階で使用できる `query` の情報がないため、 `query` は空オブジェクトになります。ハイドレーション後は、 `query` オブジェクト内のルートパラメータをアプリケーションに与えるように、 Next.js がアプリケーションを更新します。
2323

24-
> **備考:** [動的なルーティング](/docs/routing/dynamic-routes.md)と共に [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) を用いたページに与えられたパラメータは、いつでも `query` オブジェクト内で使用可能です。
24+
ハイドレーションの後にクエリが更新され、さらにレンダリングが生じるケースは以下の通りです。
25+
26+
- ページが [dynamic-route](/docs/routing/dynamic-routes.md) である場合
27+
- ページが URL にクエリの値を持っている場合
28+
- `next.config.js`[Rewrites](/docs/api-reference/next.config.js/rewrites.md) が設定されている場合。これらは `query` として解析、提供されるべきパラメータを含み得るためです。
29+
30+
クエリが全て更新され使用可能な状態になったかどうか判断するためには、[`next/router`](/docs/api-reference/next/router.md#router-object) に存在する `isReady` フィールドを利用できます。
31+
32+
> **備考:** [動的なルーティング](/docs/routing/dynamic-routes.md)と共に [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) を用いたページに与えられたパラメータは、いつでも `query` オブジェクト内で使用可能です。****
2533
2634
`next build` は静的最適化がされたページに対して `.html` ファイルを出力します。例えば、 `pages/about.js` のページに対するビルド結果は以下のようになります:
2735

2836
```bash
29-
.next/server/static/${BUILD_ID}/about.html
37+
.next/server/pages/about.html
3038
```
3139

3240
`getServerSideProps` をページに加えると、今度はビルド結果が以下のような JavaScript ファイルになります:
3341

3442
```bash
35-
.next/server/static/${BUILD_ID}/about.js
43+
.next/server/pages/about.js
3644
```
3745

3846
## 注意事項
3947

40-
- `getInitialProps` を用いた[カスタム `App` ](/docs/advanced-features/custom-app.md)の場合、[静的生成](/docs/basic-features/data-fetching.md#getstaticprops-static-generation)なしのページではこの最適化はオフになります。
48+
- `getInitialProps` を用いた[カスタム `App` ](/docs/advanced-features/custom-app.md)の場合、[静的生成](/docs/basic-features/data-fetching/get-static-props.md)なしのページではこの最適化はオフになります。
4149

4250
- `getInitialProps` を用いた[カスタム `Document` ](/docs/advanced-features/custom-document.md)の場合は、ページがサーバーサイドでレンダリングされると仮定する前に `ctx.req` が定義されているかどうかを確認してください。`ctx.req` はプリレンダリングされるページでは `undefined` になります。

docs/advanced-features/dynamic-import.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: JavaScriptモジュールとReactコンポーネントを動的に
44

55
# 動的インポート
66

7-
<details>
7+
<details open>
88
<summary><b>例</b></summary>
99
<ul>
1010
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-dynamic-import">動的インポート</a></li>
@@ -13,8 +13,36 @@ description: JavaScriptモジュールとReactコンポーネントを動的に
1313

1414
Next.js は JavaScript の ES2020 [dynamic `import()`](https://github.com/tc39/proposal-dynamic-import) をサポートしています。JavaScript モジュール(React コンポーネントを含む)を動的にインポートして使うことが出来ます。SSR にも対応しています。
1515

16+
In the following example, we implement fuzzy search using `fuse.js` and only load the module dynamically in the browser after the user types in the search input:
17+
18+
```jsx
19+
import { useState } from 'react'
20+
const names = ['Tim', 'Joe', 'Bel', 'Max', 'Lee']
21+
export default function Page() {
22+
const [results, setResults] = useState()
23+
return (
24+
<div>
25+
<input
26+
type="text"
27+
placeholder="Search"
28+
onChange={async (e) => {
29+
const { value } = e.currentTarget
30+
// Dynamically load fuse.js
31+
const Fuse = (await import('fuse.js')).default
32+
const fuse = new Fuse(names)
33+
setResults(fuse.search(value))
34+
}}
35+
/>
36+
<pre>Results: {JSON.stringify(results, null, 2)}</pre>
37+
</div>
38+
)
39+
}
40+
```
41+
1642
動的インポートは、コードを扱いやすいチャンクに分割する、もう 1 つの方法と考えることができます。
1743

44+
React components can also be imported using dynamic imports, but in this case we use it in conjunction with `next/dynamic` to make sure it works like any other React Component. Check out the sections below for more details on how it works.
45+
1846
## 基本的な使用方法
1947

2048
次の例では、`../components/hello`モジュールがページで動的に読み込まれています:
@@ -39,6 +67,8 @@ export default Home;
3967

4068
`DynamicComponent``../components/hello` から返されるデフォルトのコンポーネントです。通常の React コンポーネントのように動き、通常どおりに props を渡すことができます。
4169

70+
> **Note**: In `import('path/to/component')`, the path must be explicitly written. It can't be a template string nor a variable. Furthermore the `import()` has to be inside the `dynamic()` call for Next.js to be able to match webpack bundles / module ids to the specific `dynamic()` call and preload them before rendering. `dynamic()` can't be used inside of React rendering as it needs to be marked in the top level of the module for preloading to work, similar to `React.lazy`.
71+
4272
## 名前付きエクスポート
4373

4474
動的コンポーネントがデフォルトのエクスポートでない場合は、名前付きエクスポートも使用できます。名前付きエクスポートの `Hello` を持つ `../components/hello.js` モジュールについて考えてみましょう:
@@ -116,3 +146,23 @@ function Home() {
116146

117147
export default Home;
118148
```
149+
150+
## With suspense
151+
152+
Option `suspense` allows you to lazy-load a component, similar to `React.lazy` and `<Suspense>` with React 18. Note that it only works on client-side or server-side with `fallback`. Full SSR support in concurrent mode is still a work-in-progress.
153+
154+
```jsx
155+
import dynamic from 'next/dynamic'
156+
const DynamicLazyComponent = dynamic(() => import('../components/hello4'), {
157+
suspense: true,
158+
})
159+
function Home() {
160+
return (
161+
<div>
162+
<Suspense fallback={`loading`}>
163+
<DynamicLazyComponent />
164+
</Suspense>
165+
</div>
166+
)
167+
}
168+
```

0 commit comments

Comments
 (0)