docs: complete Chinese translation for Activity component#1882
Open
OpenKakaLucas wants to merge 2 commits intoreactjs:mainfrom
Open
docs: complete Chinese translation for Activity component#1882OpenKakaLucas wants to merge 2 commits intoreactjs:mainfrom
OpenKakaLucas wants to merge 2 commits intoreactjs:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Size changesDetails📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
loveloki
reviewed
Jan 26, 2026
| 通过这种方式,`Activity` 可以被视为一种渲染“后台活动”的机制。与其完全丢弃那些可能再次显示的内容,不如使用 `Activity` 来保持并恢复这些内容的 UI 和内部状态,同时确保隐藏的内容不会产生多余的副作用。 | ||
|
|
||
| [See more examples below.](#usage) | ||
| [请参阅下方的更多示例。](#usage) |
| </Sandpack> | ||
|
|
||
| The Overview section always starts out collapsed. Because we unmount the sidebar when `isShowingSidebar` flips to `false`, all its internal state is lost. | ||
| Overview部分最初总是处于折叠状态。因为当 `isShowingSidebar` 切换为 `false` 时,我们会卸载侧边栏,这导致其所有的内部状态都丢失了 |
Collaborator
There was a problem hiding this comment.
中文和英文之间添加空格,阅读起来更好一点。上面的 Overview 也可以考虑去掉引号改为空格
| 由于 `Activity` 边界使用 `display: none` 来隐藏其子组件,因此这些子组件的 DOM 在隐藏时也会被保留。这使得它们非常适合用于维护 UI 中那些用户可能会再次交互的部分的瞬时状态。 | ||
|
|
||
| In this example, the Contact tab has a `<textarea>` where the user can enter a message. If you enter some text, change to the Home tab, then change back to the Contact tab, the draft message is lost: | ||
| 在此示例中,`Contact`组件包含一个 `<textarea>`,用户可以在其中输入消息。如果你输入了一些文本,切换到`Home`组件,然后再切回`Contact`组件,那么草稿消息将会丢失: |
| </Sandpack> | ||
|
|
||
| This is because we're fully unmounting `Contact` in `App`. When the Contact tab unmounts, the `<textarea>` element's internal DOM state is lost. | ||
| 这是因为我们在 `App` 组件中完全卸载了 `Contact` 组件。当`Contact`组件被卸载时,`<textarea>` 元素的内部 DOM 状态也就丢失了。 |
| 这是因为我们在 `App` 组件中完全卸载了 `Contact` 组件。当`Contact`组件被卸载时,`<textarea>` 元素的内部 DOM 状态也就丢失了。 | ||
|
|
||
| If we switch to using an Activity boundary to show and hide the active tab, we can preserve the state of each tab's DOM. Try entering text and switching tabs again, and you'll see the draft message is no longer reset: | ||
| 如果我们改用 `Activity` 边界来显示和隐藏当前活跃的组件,我们就能保留每个组件的 DOM 状态。试着再次输入文本并切换组件,你会发现草稿消息不再被重置: |
Collaborator
There was a problem hiding this comment.
原文是激活的 tab,这里直接翻译为组件不知道是否合适。是不是按照原文明确一下比较好?
| 到目前为止,我们已经了解了 `Activity` 是如何在隐藏用户交互过的内容的同时,而不丢弃这些内容的瞬时状态(ephemeral state)的。 | ||
|
|
||
| But Activity boundaries can also be used to _prepare_ content that the user has yet to see for the first time: | ||
| 不仅如此,`Activity` 边界还可以用来预先准备那些用户尚未初次看到的内容: |
Collaborator
There was a problem hiding this comment.
原文的 prepare 的斜体是为了表示强调引起注意的,翻译的时候需要改成加粗来强调。
| ``` | ||
|
|
||
| When an Activity boundary is <CodeStep step={1}>hidden</CodeStep> during its initial render, its children won't be visible on the page — but they will _still be rendered_, albeit at a lower priority than the visible content, and without mounting their Effects. | ||
| 当 `Activity` 边界在初次渲染时处于 <CodeStep step={1}>隐藏</CodeStep> 状态,其子组件虽然不会在页面上显示,但它们仍会被渲染。不过,它们的渲染优先级会低于可见内容,且不会挂载它们的 Effect。 |
Collaborator
There was a problem hiding this comment.
这里也要保留原文的强调。尽量按照原文的内容来翻译,尤其是强调的地方,一般是需要重点关注的。实在不行再调整
| 当 `Activity` 边界在初次渲染时处于 <CodeStep step={1}>隐藏</CodeStep> 状态,其子组件虽然不会在页面上显示,但它们仍会被渲染。不过,它们的渲染优先级会低于可见内容,且不会挂载它们的 Effect。 | ||
|
|
||
| This _pre-rendering_ allows the children to load any code or data they need ahead of time, so that later, when the Activity boundary becomes visible, the children can appear faster with reduced loading times. | ||
| 这种“预渲染”允许子组件提前加载所需的任何代码或数据。这样一来,当随后 `Activity` 边界变为可见时,子组件就能以更短的加载时间实现更快的呈现。 |
Collaborator
There was a problem hiding this comment.
这里也是要强调的。检查下其他地方还有没有同样的问题(没有改成加粗)
| ### 加快页面加载过程中的交互速度 {/*speeding-up-interactions-during-page-load*/} | ||
|
|
||
| React includes an under-the-hood performance optimization called Selective Hydration. It works by hydrating your app's initial HTML _in chunks_, enabling some components to become interactive even if other components on the page haven't loaded their code or data yet. | ||
| React 包含一项名为“选择性注水”的底层性能优化。它的工作原理是 _分块_ 注水应用的初始 HTML,从而使部分组件即使在页面上其他组件的代码或数据尚未加载完成时,也能先变得可交互。 |
| ……但这同时也会改变 UI 表现,因为在初始渲染期间会显示 `Placeholder` 回退内容 | ||
|
|
||
| Instead, we can use Activity. Since Activity boundaries show and hide their children, they already naturally divide the component tree into independent units. And just like Suspense, this feature allows them to participate in Selective Hydration. | ||
| 相反,我们可以使用 `Activity`。由于 `Activity` 边界负责显示和隐藏其子组件,它们已经自然地将组件树划分成了彼此独立的单元。而且与 `Suspense` 一样,这一特性使得它们能够参与到“选择性注水(Selective Hydration)”中。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
摘要 (Summary)
完成了
<Activity>组件文档的完整简体中文翻译。Completed the full Simplified Chinese translation for the
<Activity>component documentation.改动类型 (Type of Change)
改动内容 (Key Changes)
我已将
<Activity>组件的所有相关页面翻译完毕,主要包括:mode属性(visible和hidden)的行为说明。<Activity>来保留离屏组件状态的示例。翻译细节说明 (Translation Details)
在翻译过程中,我严格遵循了 React 中文术语表,重点处理了以下核心概念:
mode="hidden"时,状态会被保留在内存中。示例代码核对 (Code Snippet Check)
翻译后的代码注释已同步更新,确保中文开发者能清晰理解逻辑: