From 3e0cf9769d5e66d1b833d4b485f180b719a566b9 Mon Sep 17 00:00:00 2001 From: Naoki Endoh Date: Tue, 13 Apr 2021 17:13:00 +0900 Subject: [PATCH 1/2] feat: add migration guide > suspense --- src/.vuepress/config.js | 1 + src/guide/migration/suspense.md | 107 ++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 src/guide/migration/suspense.md diff --git a/src/.vuepress/config.js b/src/.vuepress/config.js index d3449d63..d7de58d0 100644 --- a/src/.vuepress/config.js +++ b/src/.vuepress/config.js @@ -131,6 +131,7 @@ const sidebar = { 'migration/props-default-this', 'migration/render-function-api', 'migration/slots-unification', + 'migration/suspense', 'migration/transition', 'migration/v-if-v-for', 'migration/v-model', diff --git a/src/guide/migration/suspense.md b/src/guide/migration/suspense.md new file mode 100644 index 00000000..4122f423 --- /dev/null +++ b/src/guide/migration/suspense.md @@ -0,0 +1,107 @@ +--- +badges: + - new +--- + +# Suspense + +:::warning Experimental +Suspense is an experimental new feature and the API could change at any time. It is documented here so that the community can provide feedback on the current implementation. + +It should not be used in production applications. +::: + +## Introduction + +It is common for components to need to perform some kind of asynchronous request before they can be rendered properly. Components often handle this locally and in many cases that is a perfectly good approach. + +The `` component provides an alternative, allowing for the waiting to be handled further up the component tree rather than in each individual component. + +A common use case involves [async components](/guide/component-dynamic-async.html#async-components): + +```vue{2-4,6,17} + + + +``` + +The `` component has two slots. Both slots only allow for one immediate child node. The node in the `default` slot is shown if possible. If not, the node in the `fallback` slot will be shown instead. + +Importantly, the async component doesn't need to be the immediate child of the ``. It can be at any depth within the component tree and doesn't need to appear in the same template as the `` itself. The content is only considered resolved once all descendants are ready. + +The other way to trigger the `fallback` slot is for a descendant component to return a promise from its `setup` function. This is typically implemented using `async` rather than explicitly returning a promise: + +```js{2} +export default { + async setup() { + // Be very careful using `await` inside `setup` as + // most Composition API functions will only work + // prior to the first `await` + const data = await loadData() + + // This is implicitly wrapped in a promise because + // the function is `async` + return { + // ... + } + } +} +``` + +## Child Updates + +Once a `` has resolved the contents of its `default` slot, it can only be triggered again if the `default` root node is replaced. New components nested deeper in the tree are not sufficient to move the `` back into a pending state. + +If the root node does change it will trigger the `pending` event. However, by default, it won't update the DOM to show the `fallback` content. Instead, it will continue to show the old DOM until the new components are ready. This can be controlled using the `timeout` prop. This value, expressed in milliseconds, tells the `` component how long to wait before showing the `fallback`. A value of `0` will show it immediately when the `` enters the pending state. + +## Events + +In addition to the `pending` event, the `` component also has `resolve` and `fallback` events. The `resolve` event is emitted when new content has finished resolving in the `default` slot. The `fallback` event is fired when the contents of the `fallback` slot are shown. + +The events could be used, for example, to show a loading indicator in front of the old DOM while new components are loading. + +## Combining with Other Components + +It is common to want to use `` in combination with the [``](/api/built-in-components.html#transition) and [``](/api/built-in-components.html#keep-alive) components. The nesting order of these components is important to get them all working correctly. + +In addition, these components are often used in conjunction with the `` component from [Vue Router](https://next.router.vuejs.org/). + +The following example shows how to nest these components so that they all behave as expected. For simpler combinations you can remove the components that you don't need: + +```html + + + +``` + +Vue Router has built-in support for [lazily loading components](https://next.router.vuejs.org/guide/advanced/lazy-loading.html) using dynamic imports. These are distinct from async components and currently they will not trigger ``. However, they can still have async components as descendants and those can trigger `` in the usual way. From aa8d35fb01923b33ff382dff3f78e3636aa36493 Mon Sep 17 00:00:00 2001 From: Naoki Endoh Date: Tue, 13 Apr 2021 19:54:47 +0900 Subject: [PATCH 2/2] docs: translate migration guide > suspense --- src/guide/migration/suspense.md | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/guide/migration/suspense.md b/src/guide/migration/suspense.md index 4122f423..038bba17 100644 --- a/src/guide/migration/suspense.md +++ b/src/guide/migration/suspense.md @@ -5,19 +5,19 @@ badges: # Suspense -:::warning Experimental -Suspense is an experimental new feature and the API could change at any time. It is documented here so that the community can provide feedback on the current implementation. +:::warning 実験的 +Suspense は実験的な新機能であり、 API はいつでも変更される可能性があります。コミュニティが現在の実装についてフィードバックできるように、ここにドキュメント化されています。 -It should not be used in production applications. +本番のアプリケーションでは使用しないでください。 ::: -## Introduction +## イントロダクション -It is common for components to need to perform some kind of asynchronous request before they can be rendered properly. Components often handle this locally and in many cases that is a perfectly good approach. +コンポーネントが正しくレンダリングされる前に、なにか非同期のリクエストを実行する必要があるのはよくあることです。コンポーネントはローカルでよくこの処理をしますが、多くの場合にこれは優れたアプローチです。 -The `` component provides an alternative, allowing for the waiting to be handled further up the component tree rather than in each individual component. +`` コンポーネントは、個々のコンポーネントではなくコンポーネントツリーのさらに上で待機処理できるように、代替手段を提供します。 -A common use case involves [async components](/guide/component-dynamic-async.html#async-components): +よくある使用例は、 [非同期コンポーネント](/guide/component-dynamic-async.html#async-components) があります: ```vue{2-4,6,17}