Skip to content

"Client Side Hydration" の翻訳 #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 20, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions ja/hydration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# クライアントサイドでのハイドレーション

`entry-client.js` 中、以下の記述で私たちは簡単にアプリケーションをマウントします。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"entry-client.js 中"ではなく、"entry-client.js において" の方が、読み手に理解しやすいでしょう!


```js
// これは、ルート要素に id="app" をもつ App.vue テンプレートを想定します。
app.$mount('#app')
```

サーバがマークアップを描画後に、この処理を実行し、DOM を再生成することを私たちは当然したくありません。代わりに、静的なマークアップの「ハイドレート」とそれをインタラクティブに生成したいと思います。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the DOM elementsall が抜けています!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ダブルクォーテーションは、「」ではなく、そのままダブルクォーテーションでお願いします!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

思います。ではなく、want toなので、したいです。が望ましいですね。


もしあなたがサーバレンダリングの出力を調べたら、アプリケーションのルート要素が以下のような特別な属性を持っていることに気づくでしょう。

```js
<div id="app" data-server-rendered="true">
```

この `data-server-rendered` という特別な属性は、クライアントサイドの Vue に、これがサーバ上で描画されたことを知らせ、この要素はハイドレーションモードでマウントされるはずです。

ディベロップメントモードでは、Vue はクラインアントサイドで生成された仮想 DOM が、サーバで描画された DOM の構成とマッチしているかアサーションを行います。もしこれがマッチしていない場合、ハイドレーションを取りやめ、元の DOM を無視しスクラッチから描画を行います。**プロダクションモードでは、パフォーマンスの最大化のため、このアサーションは無効になります。**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ディベロップメントモード開発モードでお願いします!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここでのassertion検証でオネガイします!


### ハイドレーション時の注意

サーバサイドレンダリングとクライアントサイドでのハイドレーションを行なった場合、ある特定の HTML の構造はブラウザによって変換されるかもしれないことがわかっています。例えば、あなたが Vueのテンプレート内に、以下のような記述をした場合です。

```html
<table>
<tr><td>hi</td></tr>
</table>
```

ブラウザは、自動で `<tbody>` を `<table>` に挿入します。しかし、Vue によって生成された仮想 DOM は、`<tbody>` を含みません。そのため、ミスマッチが起こります。正しいマッチングを保証するために、あなたのテンプレート内では、必ず有効な HTML を記述してください。