-
Notifications
You must be signed in to change notification settings - Fork 9
"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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# クライアントサイドでのハイドレーション | ||
|
||
`entry-client.js` 中、以下の記述で私たちは簡単にアプリケーションをマウントします。 | ||
|
||
```js | ||
// これは、ルート要素に id="app" をもつ App.vue テンプレートを想定します。 | ||
app.$mount('#app') | ||
``` | ||
|
||
サーバがマークアップを描画後に、この処理を実行し、DOM を再生成することを私たちは当然したくありません。代わりに、静的なマークアップの「ハイドレート」とそれをインタラクティブに生成したいと思います。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ダブルクォーテーションは、 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
もしあなたがサーバレンダリングの出力を調べたら、アプリケーションのルート要素が以下のような特別な属性を持っていることに気づくでしょう。 | ||
|
||
```js | ||
<div id="app" data-server-rendered="true"> | ||
``` | ||
|
||
この `data-server-rendered` という特別な属性は、クライアントサイドの Vue に、これがサーバ上で描画されたことを知らせ、この要素はハイドレーションモードでマウントされるはずです。 | ||
|
||
ディベロップメントモードでは、Vue はクラインアントサイドで生成された仮想 DOM が、サーバで描画された DOM の構成とマッチしているかアサーションを行います。もしこれがマッチしていない場合、ハイドレーションを取りやめ、元の DOM を無視しスクラッチから描画を行います。**プロダクションモードでは、パフォーマンスの最大化のため、このアサーションは無効になります。** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここでの |
||
|
||
### ハイドレーション時の注意 | ||
|
||
サーバサイドレンダリングとクライアントサイドでのハイドレーションを行なった場合、ある特定の HTML の構造はブラウザによって変換されるかもしれないことがわかっています。例えば、あなたが Vueのテンプレート内に、以下のような記述をした場合です。 | ||
|
||
```html | ||
<table> | ||
<tr><td>hi</td></tr> | ||
</table> | ||
``` | ||
|
||
ブラウザは、自動で `<tbody>` を `<table>` に挿入します。しかし、Vue によって生成された仮想 DOM は、`<tbody>` を含みません。そのため、ミスマッチが起こります。正しいマッチングを保証するために、あなたのテンプレート内では、必ず有効な HTML を記述してください。 |
There was a problem hiding this comment.
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
において" の方が、読み手に理解しやすいでしょう!