From 3ad3ca234861aca81f27a8dc941dc867be90863b Mon Sep 17 00:00:00 2001
From: Lcina <870206584@qq.com>
Date: Sat, 2 Mar 2019 11:17:46 +0800
Subject: [PATCH 01/36] feat: Complete the translation of the
---
content/docs/error-boundaries.md | 84 ++++++++++++++++----------------
1 file changed, 42 insertions(+), 42 deletions(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 1477329112..fb1ff8ca9e 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -4,25 +4,25 @@ title: Error Boundaries
permalink: docs/error-boundaries.html
---
-In the past, JavaScript errors inside components used to corrupt React’s internal state and cause it to [emit](https://github.com/facebook/react/issues/4026) [cryptic](https://github.com/facebook/react/issues/6895) [errors](https://github.com/facebook/react/issues/8579) on next renders. These errors were always caused by an earlier error in the application code, but React did not provide a way to handle them gracefully in components, and could not recover from them.
+过去,组件内的 JavaScript 错误会导致 React 的内部状态被破坏,并且在下一次渲染时 [产生](https://github.com/facebook/react/issues/4026) [可能无法追踪的](https://github.com/facebook/react/issues/6895) [错误](https://github.com/facebook/react/issues/8579)。这些错误基本上是由应用代码中较早的错误引起的,但 React 并没有提供一种在组件中优雅处理这些错误的方式,也无法从错误中恢复。
-## Introducing Error Boundaries {#introducing-error-boundaries}
+## 介绍错误边界(Error Boundaries) {#introducing-error-boundaries}
-A JavaScript error in a part of the UI shouldn’t break the whole app. To solve this problem for React users, React 16 introduces a new concept of an “error boundary”.
+部分 UI 的 JavaScript 错误不应该导致整个应用崩溃,为了解决 React 用户这个问题,React 16 引入了一个新的概念 —— 错误边界。
-Error boundaries are React components that **catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI** instead of the component tree that crashed. Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.
+错误边界是 **用于捕获子组件树中任意位置的 JavaScript 错误,记录错误并显示一个备用 UI** 的 React 组件,而不是使整个组件树崩溃。 错误边界在渲染期间、生命周期方法和整个组件树的构造函数中捕获错误。
-> Note
+> 注意
>
-> Error boundaries do **not** catch errors for:
+> 错误边界 **无法** 捕获如下错误:
>
-> * Event handlers ([learn more](#how-about-event-handlers))
-> * Asynchronous code (e.g. `setTimeout` or `requestAnimationFrame` callbacks)
-> * Server side rendering
-> * Errors thrown in the error boundary itself (rather than its children)
+> * 事件处理([了解更多](#how-about-event-handlers))
+> * 异步代码(例如 `setTimeout` 或 `requestAnimationFrame` 回调函数)
+> * 服务端渲染
+> * 它自身抛出来的错误(并非它的子组件)
-A class component becomes an error boundary if it defines either (or both) of the lifecycle methods [`static getDerivedStateFromError()`](/docs/react-component.html#static-getderivedstatefromerror) or [`componentDidCatch()`](/docs/react-component.html#componentdidcatch). Use `static getDerivedStateFromError()` to render a fallback UI after an error has been thrown. Use `componentDidCatch()` to log error information.
+如果一个类组件中定义了生命周期方法 [`static getDerivedStateFromError()`](/docs/react-component.html#static-getderivedstatefromerror) 或 [`componentDidCatch()`](/docs/react-component.html#componentdidcatch) 中的任意一个(或两个),那么它就变成一个错误边界 (error boundary)。当抛出错误后,使用 `static getDerivedStateFromError()` 渲染备用 UI ,使用 `componentDidCatch()` 记录错误信息。
```js{7-10,12-15,18-21}
class ErrorBoundary extends React.Component {
@@ -52,7 +52,7 @@ class ErrorBoundary extends React.Component {
}
```
-Then you can use it as a regular component:
+然后你可以将它作为一个常规组件去使用:
```js
@@ -60,53 +60,53 @@ Then you can use it as a regular component:
```
-Error boundaries work like a JavaScript `catch {}` block, but for components. Only class components can be error boundaries. In practice, most of the time you’ll want to declare an error boundary component once and use it throughout your application.
+错误边界的工作方式类似于 JavaScript `catch {}`,但只是针对组件。只有类组件可以是错误边界,实际上大多数情况下, 您需要声明一次错误边界组件, 并在整个应用程序中使用它。
-Note that **error boundaries only catch errors in the components below them in the tree**. An error boundary can’t catch an error within itself. If an error boundary fails trying to render the error message, the error will propagate to the closest error boundary above it. This, too, is similar to how catch {} block works in JavaScript.
+注意 **错误边界仅可以捕获其子组件的错误** ,它无法捕获其自身的错误。如果一个错误边界无法渲染错误信息,则错误会采用就近原则,冒泡至最接近的错误边界,这也类似于 JavaScript 中 catch {} 的工作机制。
-## Live Demo {#live-demo}
+## 在线演示 {#live-demo}
-Check out [this example of declaring and using an error boundary](https://codepen.io/gaearon/pen/wqvxGa?editors=0010) with [React 16](/blog/2017/09/26/react-v16.0.html).
+查看通过 [React 16](/blog/2017/09/26/react-v16.0.html) [定义和使用错误边界的例子](/blog/2017/09/26/react-v16.0.html)。
-## Where to Place Error Boundaries {#where-to-place-error-boundaries}
+## 放置错误边界的位置 {#where-to-place-error-boundaries}
-The granularity of error boundaries is up to you. You may wrap top-level route components to display a “Something went wrong” message to the user, just like server-side frameworks often handle crashes. You may also wrap individual widgets in an error boundary to protect them from crashing the rest of the application.
+错误边界的粒度由你来决定,可以将其包装在最顶层的路由组件并为用户展示一个 “Something went wrong” 的错误信息,就像服务端框架经常处理崩溃一样。你也可以将单独的部件包装在错误边界以保护应用其他部分不崩溃。
-## New Behavior for Uncaught Errors {#new-behavior-for-uncaught-errors}
+## 未捕获错误(Uncaught Errors)的新行为 {#new-behavior-for-uncaught-errors}
-This change has an important implication. **As of React 16, errors that were not caught by any error boundary will result in unmounting of the whole React component tree.**
+这一改变具有重要意义,**自 React 16 起,任何未被错误边界捕获的错误将会导致整个 React 组件树被卸载。**
-We debated this decision, but in our experience it is worse to leave corrupted UI in place than to completely remove it. For example, in a product like Messenger leaving the broken UI visible could lead to somebody sending a message to the wrong person. Similarly, it is worse for a payments app to display a wrong amount than to render nothing.
+我们对这一决定饱含争论,但在我们的经验中放置一个错误的 UI 比完全移除它要更糟糕。例如,在类似 Messenger 的产品中留下一个异常可见的 UI 可能会导致用户将信息错发给别人。同样,对于支付类应用而言,显示错误的金额也比不呈现任何内容更糟糕。
-This change means that as you migrate to React 16, you will likely uncover existing crashes in your application that have been unnoticed before. Adding error boundaries lets you provide better user experience when something goes wrong.
+此变化意味着当你迁入到 React 16 时,你可能会发现一些已存在你应用中但未曾注意到的崩溃。增加错误边界能够让你在应用发生异常时提供更好的用户体验。
-For example, Facebook Messenger wraps content of the sidebar, the info panel, the conversation log, and the message input into separate error boundaries. If some component in one of these UI areas crashes, the rest of them remain interactive.
+例如,Facebook Messenger 将侧边栏、信息面板、对话框以及信息输入框包装在单独的错误边界中。如果其中的某些 UI 组件崩溃,其余部分仍然能够交互。
-We also encourage you to use JS error reporting services (or build your own) so that you can learn about unhandled exceptions as they happen in production, and fix them.
+我们也鼓励使用 JS 错误报告服务(或自行构建),这样你能了解关于生产环境中出现的未捕获异常,并将其修复。
-## Component Stack Traces {#component-stack-traces}
+## 组件栈追踪 {#component-stack-traces}
-React 16 prints all errors that occurred during rendering to the console in development, even if the application accidentally swallows them. In addition to the error message and the JavaScript stack, it also provides component stack traces. Now you can see where exactly in the component tree the failure has happened:
+React 16 会在渲染期间将所有在开发环境下抛出的错误打印到控制台,即使应用程序意外的将其掩盖。除了错误信息和 JavaScript 栈外,它还提供了组件栈追踪。现在你可以准确地查看发生在组件树内的错误信息:
-You can also see the filenames and line numbers in the component stack trace. This works by default in [Create React App](https://github.com/facebookincubator/create-react-app) projects:
+你也可以在组件栈追踪中查看文件名和行号,这一功能在 [Create React App](https://github.com/facebookincubator/create-react-app) 项目中默认开启:
-If you don’t use Create React App, you can add [this plugin](https://www.npmjs.com/package/babel-plugin-transform-react-jsx-source) manually to your Babel configuration. Note that it’s intended only for development and **must be disabled in production**.
+如果你没有使用 Create React App ,可以手动将[该插件](https://www.npmjs.com/package/babel-plugin-transform-react-jsx-source)添加到你的 Babel 配置中。注意它仅可在开发环境下使用,而 **生产环境必须将其禁用** 。
-> Note
+> 注意
>
-> Component names displayed in the stack traces depend on the [`Function.name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) property. If you support older browsers and devices which may not yet provide this natively (e.g. IE 11), consider including a `Function.name` polyfill in your bundled application, such as [`function.name-polyfill`](https://github.com/JamesMGreene/Function.name). Alternatively, you may explicitly set the [`displayName`](/docs/react-component.html#displayname) property on all your components.
+> 组件名称在栈追踪中的显示依赖于 [`Function.name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) 属性。如果你想要支持尚未提供该功能的旧版浏览器和设备(例如 IE 11),考虑在你的打包(bundled)应用程序中包含一个 `Function.name` 的 polyfill,如 [`function.name-polyfill`](https://github.com/JamesMGreene/Function.name) 。或者,你可以在所有组件上显式设置 [`displayName`](/docs/react-component.html#displayname) 属性。
-## How About try/catch? {#how-about-trycatch}
+## 关于 try/catch ? {#how-about-trycatch}
-`try` / `catch` is great but it only works for imperative code:
+`try` / `catch` 很棒但它仅能用于命令式代码(imperative code):
```js
try {
@@ -116,21 +116,21 @@ try {
}
```
-However, React components are declarative and specify *what* should be rendered:
+然而,React 组件是声明式的并且具体指出 *什么* 需要被渲染:
```js
```
-Error boundaries preserve the declarative nature of React, and behave as you would expect. For example, even if an error occurs in a `componentDidUpdate` method caused by a `setState` somewhere deep in the tree, it will still correctly propagate to the closest error boundary.
+错误边界保留了 React 的声明性质,其行为符合你的预期。例如,即使一个错误发生在 `componentDidUpdate` 方法中,由某一个深层组件树的 `setState` 引起,其仍然能够冒泡到最近的错误边界。
-## How About Event Handlers? {#how-about-event-handlers}
+## 关于事件处理器 {#how-about-event-handlers}
-Error boundaries **do not** catch errors inside event handlers.
+错误边界 **无法** 捕获事件处理器内部的错误。
-React doesn't need error boundaries to recover from errors in event handlers. Unlike the render method and lifecycle methods, the event handlers don't happen during rendering. So if they throw, React still knows what to display on the screen.
+React 不需要错误边界来从事件处理程序的错误中恢复。与渲染方法和生命周期钩子不同,事件处理器不会在渲染期间触发。因此,如果它们抛出异常,React 仍然能够知道需要在屏幕上显示什么。
-If you need to catch an error inside event handler, use the regular JavaScript `try` / `catch` statement:
+如果你需要在事件处理器内部捕获错误,使用普通的 JavaScript `try` / `catch` 语句:
```js{9-13,17-20}
class MyComponent extends React.Component {
@@ -157,10 +157,10 @@ class MyComponent extends React.Component {
}
```
-Note that the above example is demonstrating regular JavaScript behavior and doesn't use error boundaries.
+请注意上述例子只是演示了普通的 JavaScript 行为,并没有使用错误边界。
-## Naming Changes from React 15 {#naming-changes-from-react-15}
+## 自 React 15 的命名更改 {#naming-changes-from-react-15}
-React 15 included a very limited support for error boundaries under a different method name: `unstable_handleError`. This method no longer works, and you will need to change it to `componentDidCatch` in your code starting from the first 16 beta release.
+React 15 在一个不同的方法名下:`unstable_handleError` 包含了一个支持有限的错误边界。此方法不再起作用,同时自 React 16 beta 发布起你需要在代码中将其修改为 `componentDidCatch` 。
-For this change, we’ve provided a [codemod](https://github.com/reactjs/react-codemod#error-boundaries) to automatically migrate your code.
+对此,我们已提供了一个 [codemod](https://github.com/reactjs/react-codemod#error-boundaries) 来帮助你自动迁移你的代码。
From 977864a6bf25e7bead5844e3953cd36db91e6727 Mon Sep 17 00:00:00 2001
From: hateonion
Date: Wed, 6 Mar 2019 10:45:37 +0800
Subject: [PATCH 02/36] Update content/docs/error-boundaries.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
fix: translate `introducing-error-boundaries` to “错误边界介绍”.
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index fb1ff8ca9e..537e975ea2 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -7,7 +7,7 @@ permalink: docs/error-boundaries.html
过去,组件内的 JavaScript 错误会导致 React 的内部状态被破坏,并且在下一次渲染时 [产生](https://github.com/facebook/react/issues/4026) [可能无法追踪的](https://github.com/facebook/react/issues/6895) [错误](https://github.com/facebook/react/issues/8579)。这些错误基本上是由应用代码中较早的错误引起的,但 React 并没有提供一种在组件中优雅处理这些错误的方式,也无法从错误中恢复。
-## 介绍错误边界(Error Boundaries) {#introducing-error-boundaries}
+## 错误边界介绍(Error Boundaries) {#introducing-error-boundaries}
部分 UI 的 JavaScript 错误不应该导致整个应用崩溃,为了解决 React 用户这个问题,React 16 引入了一个新的概念 —— 错误边界。
From 4e41c5a8db9a54a68aab4b2777841f67dcdd54e4 Mon Sep 17 00:00:00 2001
From: hateonion
Date: Wed, 6 Mar 2019 10:49:17 +0800
Subject: [PATCH 03/36] Update content/docs/error-boundaries.md
fix: merge suggestion.
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 537e975ea2..a225b94ec6 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -9,7 +9,7 @@ permalink: docs/error-boundaries.html
## 错误边界介绍(Error Boundaries) {#introducing-error-boundaries}
-部分 UI 的 JavaScript 错误不应该导致整个应用崩溃,为了解决 React 用户这个问题,React 16 引入了一个新的概念 —— 错误边界。
+部分 UI 的 JavaScript 错误不应该导致整个应用崩溃,为了解决这个问题,React 16 引入了一个新的概念 —— 错误边界。
错误边界是 **用于捕获子组件树中任意位置的 JavaScript 错误,记录错误并显示一个备用 UI** 的 React 组件,而不是使整个组件树崩溃。 错误边界在渲染期间、生命周期方法和整个组件树的构造函数中捕获错误。
From 3b79d55c97f591e10f14078b4b8fb3ab53281f94 Mon Sep 17 00:00:00 2001
From: Lcina
Date: Wed, 6 Mar 2019 10:52:53 +0800
Subject: [PATCH 04/36] Update error-boundaries.md
fix: merge suggestion.
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index a225b94ec6..f0f25ce4dc 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -4,7 +4,7 @@ title: Error Boundaries
permalink: docs/error-boundaries.html
---
-过去,组件内的 JavaScript 错误会导致 React 的内部状态被破坏,并且在下一次渲染时 [产生](https://github.com/facebook/react/issues/4026) [可能无法追踪的](https://github.com/facebook/react/issues/6895) [错误](https://github.com/facebook/react/issues/8579)。这些错误基本上是由应用代码中较早的错误引起的,但 React 并没有提供一种在组件中优雅处理这些错误的方式,也无法从错误中恢复。
+过去,组件内的 JavaScript 错误会导致 React 的内部状态被破坏,并且在下一次渲染时 [产生](https://github.com/facebook/react/issues/4026) [可能无法追踪的](https://github.com/facebook/react/issues/6895) [错误](https://github.com/facebook/react/issues/8579)。这些错误基本上是由其他代码(非React组件代码)中较早的错误引起的,但 React 并没有提供一种在组件中优雅处理这些错误的方式,也无法从错误中恢复。
## 错误边界介绍(Error Boundaries) {#introducing-error-boundaries}
From 22d69b74de594b101682653c2a46305f8c4afdbf Mon Sep 17 00:00:00 2001
From: hateonion
Date: Wed, 20 Mar 2019 22:55:59 +0800
Subject: [PATCH 05/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index f0f25ce4dc..86c0680781 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -15,7 +15,7 @@ permalink: docs/error-boundaries.html
> 注意
>
-> 错误边界 **无法** 捕获如下错误:
+> 错误边界 **无法** 捕获以下场景中产生的错误:
>
> * 事件处理([了解更多](#how-about-event-handlers))
> * 异步代码(例如 `setTimeout` 或 `requestAnimationFrame` 回调函数)
From afeecc91c6511b6daaa77c23f71286719facc7a1 Mon Sep 17 00:00:00 2001
From: junjun
Date: Thu, 21 Mar 2019 19:22:42 +0800
Subject: [PATCH 06/36] Update content/docs/error-boundaries.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
好,确实有点奇怪
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 86c0680781..1621f2eb0c 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -7,7 +7,7 @@ permalink: docs/error-boundaries.html
过去,组件内的 JavaScript 错误会导致 React 的内部状态被破坏,并且在下一次渲染时 [产生](https://github.com/facebook/react/issues/4026) [可能无法追踪的](https://github.com/facebook/react/issues/6895) [错误](https://github.com/facebook/react/issues/8579)。这些错误基本上是由其他代码(非React组件代码)中较早的错误引起的,但 React 并没有提供一种在组件中优雅处理这些错误的方式,也无法从错误中恢复。
-## 错误边界介绍(Error Boundaries) {#introducing-error-boundaries}
+## 错误边界(Error Boundaries) {#introducing-error-boundaries}
部分 UI 的 JavaScript 错误不应该导致整个应用崩溃,为了解决这个问题,React 16 引入了一个新的概念 —— 错误边界。
From 0e43012aef7cea9b54693550fd1ffd6de507f3cc Mon Sep 17 00:00:00 2001
From: hateonion
Date: Thu, 21 Mar 2019 19:25:37 +0800
Subject: [PATCH 07/36] Update content/docs/error-boundaries.md
merge
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 1621f2eb0c..69ad646d91 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -22,7 +22,7 @@ permalink: docs/error-boundaries.html
> * 服务端渲染
> * 它自身抛出来的错误(并非它的子组件)
-如果一个类组件中定义了生命周期方法 [`static getDerivedStateFromError()`](/docs/react-component.html#static-getderivedstatefromerror) 或 [`componentDidCatch()`](/docs/react-component.html#componentdidcatch) 中的任意一个(或两个),那么它就变成一个错误边界 (error boundary)。当抛出错误后,使用 `static getDerivedStateFromError()` 渲染备用 UI ,使用 `componentDidCatch()` 记录错误信息。
+如果一个类组件中定义了 [`static getDerivedStateFromError()`](/docs/react-component.html#static-getderivedstatefromerror) 或 [`componentDidCatch()`](/docs/react-component.html#componentdidcatch) 这两个生命周期方法中的任意一个(或两个)时,那么它就变成一个错误边界 (error boundary)。当抛出错误后,请使用使用 `static getDerivedStateFromError()` 渲染备用 UI ,使用 `componentDidCatch()` 记录错误信息。
```js{7-10,12-15,18-21}
class ErrorBoundary extends React.Component {
From 6cd5997712e6be4988461fac0f0bf060a3a7b76d Mon Sep 17 00:00:00 2001
From: hateonion
Date: Thu, 21 Mar 2019 19:26:22 +0800
Subject: [PATCH 08/36] Update content/docs/error-boundaries.md
merge
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 69ad646d91..636d384bfe 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -69,7 +69,7 @@ class ErrorBoundary extends React.Component {
查看通过 [React 16](/blog/2017/09/26/react-v16.0.html) [定义和使用错误边界的例子](/blog/2017/09/26/react-v16.0.html)。
-## 放置错误边界的位置 {#where-to-place-error-boundaries}
+## 错误边界应该放置在哪? {#where-to-place-error-boundaries}
错误边界的粒度由你来决定,可以将其包装在最顶层的路由组件并为用户展示一个 “Something went wrong” 的错误信息,就像服务端框架经常处理崩溃一样。你也可以将单独的部件包装在错误边界以保护应用其他部分不崩溃。
From f9d53a0527454ada375e0926e2fa1724f16a981b Mon Sep 17 00:00:00 2001
From: hateonion
Date: Thu, 21 Mar 2019 19:27:00 +0800
Subject: [PATCH 09/36] Update content/docs/error-boundaries.md
merge
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 636d384bfe..16108de736 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -78,7 +78,7 @@ class ErrorBoundary extends React.Component {
这一改变具有重要意义,**自 React 16 起,任何未被错误边界捕获的错误将会导致整个 React 组件树被卸载。**
-我们对这一决定饱含争论,但在我们的经验中放置一个错误的 UI 比完全移除它要更糟糕。例如,在类似 Messenger 的产品中留下一个异常可见的 UI 可能会导致用户将信息错发给别人。同样,对于支付类应用而言,显示错误的金额也比不呈现任何内容更糟糕。
+React 开发团队内部对这一决定有过一些争论,但在我们的经验中放置一个错误的 UI 比完全移除它要更糟糕。例如,在类似 Messenger 的产品中让一个异常的 UI 对用户可见可能会导致用户将信息错发给别人。同样,对于支付类应用而言,显示错误的金额也比不呈现任何内容更糟糕。
此变化意味着当你迁入到 React 16 时,你可能会发现一些已存在你应用中但未曾注意到的崩溃。增加错误边界能够让你在应用发生异常时提供更好的用户体验。
From ef7eb8526f16571685da12f12f264c337515fdb1 Mon Sep 17 00:00:00 2001
From: hateonion
Date: Thu, 21 Mar 2019 19:27:55 +0800
Subject: [PATCH 10/36] Update content/docs/error-boundaries.md
merge
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 16108de736..707cc31081 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -89,7 +89,7 @@ React 开发团队内部对这一决定有过一些争论,但在我们的经
## 组件栈追踪 {#component-stack-traces}
-React 16 会在渲染期间将所有在开发环境下抛出的错误打印到控制台,即使应用程序意外的将其掩盖。除了错误信息和 JavaScript 栈外,它还提供了组件栈追踪。现在你可以准确地查看发生在组件树内的错误信息:
+React 16 会在渲染期间将所有在开发环境下抛出的错误打印到控制台,即使应用程序意外的将其掩盖。除了错误信息和 JavaScript 栈外,React 16 还提供了组件栈追踪。现在你可以准确地查看发生在组件树内的错误信息:
From 00785b745303943505d55f890c432e56ae3af627 Mon Sep 17 00:00:00 2001
From: Lcina
Date: Thu, 21 Mar 2019 19:32:53 +0800
Subject: [PATCH 11/36] Update error-boundaries.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
优化翻译
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 707cc31081..9cc9fce54f 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -11,7 +11,7 @@ permalink: docs/error-boundaries.html
部分 UI 的 JavaScript 错误不应该导致整个应用崩溃,为了解决这个问题,React 16 引入了一个新的概念 —— 错误边界。
-错误边界是 **用于捕获子组件树中任意位置的 JavaScript 错误,记录错误并显示一个备用 UI** 的 React 组件,而不是使整个组件树崩溃。 错误边界在渲染期间、生命周期方法和整个组件树的构造函数中捕获错误。
+错误边界并不会使整个组件树崩溃,它是 **用于捕获子组件树中任意位置的 JavaScript 错误,记录错误并显示一个备用 UI** 的 React 组件。 错误边界在渲染期间、生命周期方法和整个组件树的构造函数中捕获错误。
> 注意
>
From 3340234bdc09a6c2099627a28c6bcab4e3e46c77 Mon Sep 17 00:00:00 2001
From: Lcina
Date: Thu, 21 Mar 2019 19:37:06 +0800
Subject: [PATCH 12/36] Update error-boundaries.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
优化翻译
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 9cc9fce54f..69fc65e319 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -60,7 +60,7 @@ class ErrorBoundary extends React.Component {
```
-错误边界的工作方式类似于 JavaScript `catch {}`,但只是针对组件。只有类组件可以是错误边界,实际上大多数情况下, 您需要声明一次错误边界组件, 并在整个应用程序中使用它。
+错误边界的工作方式类似于 JavaScript `catch {}`,不同的地方在于错误边界只针对 React 组件。只有类组件可以通过实现指定的方法变成错误边界组件,实际上大多数情况下, 您需要声明一次错误边界组件, 并在整个应用程序中使用它。
注意 **错误边界仅可以捕获其子组件的错误** ,它无法捕获其自身的错误。如果一个错误边界无法渲染错误信息,则错误会采用就近原则,冒泡至最接近的错误边界,这也类似于 JavaScript 中 catch {} 的工作机制。
From af078f87c99bfc3af91549a12ea74381efdca239 Mon Sep 17 00:00:00 2001
From: junjun
Date: Wed, 27 Mar 2019 14:40:16 +0800
Subject: [PATCH 13/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 69fc65e319..c693b136a4 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -4,7 +4,7 @@ title: Error Boundaries
permalink: docs/error-boundaries.html
---
-过去,组件内的 JavaScript 错误会导致 React 的内部状态被破坏,并且在下一次渲染时 [产生](https://github.com/facebook/react/issues/4026) [可能无法追踪的](https://github.com/facebook/react/issues/6895) [错误](https://github.com/facebook/react/issues/8579)。这些错误基本上是由其他代码(非React组件代码)中较早的错误引起的,但 React 并没有提供一种在组件中优雅处理这些错误的方式,也无法从错误中恢复。
+过去,组件内的 JavaScript 错误会导致 React 的内部状态被破坏,并且在下一次渲染时 [产生](https://github.com/facebook/react/issues/4026) [可能无法追踪的](https://github.com/facebook/react/issues/6895) [错误](https://github.com/facebook/react/issues/8579)。这些错误基本上是由较早的其他代码(非React组件代码)错误引起的,但 React 并没有提供一种在组件中优雅处理这些错误的方式,也无法从错误中恢复。
## 错误边界(Error Boundaries) {#introducing-error-boundaries}
From 67a2538a5c5c9147cdd1811254d77cbedf04b8c4 Mon Sep 17 00:00:00 2001
From: junjun
Date: Wed, 27 Mar 2019 14:40:49 +0800
Subject: [PATCH 14/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index c693b136a4..a417f80a61 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -60,7 +60,7 @@ class ErrorBoundary extends React.Component {
```
-错误边界的工作方式类似于 JavaScript `catch {}`,不同的地方在于错误边界只针对 React 组件。只有类组件可以通过实现指定的方法变成错误边界组件,实际上大多数情况下, 您需要声明一次错误边界组件, 并在整个应用程序中使用它。
+错误边界的工作方式类似于 JavaScript `catch {}`,不同的地方在于错误边界只针对 React 组件。只有 class 组件可以通过实现指定的方法变成错误边界组件,实际上大多数情况下, 您需要声明一次错误边界组件, 并在整个应用程序中使用它。
注意 **错误边界仅可以捕获其子组件的错误** ,它无法捕获其自身的错误。如果一个错误边界无法渲染错误信息,则错误会采用就近原则,冒泡至最接近的错误边界,这也类似于 JavaScript 中 catch {} 的工作机制。
From 914d358bdb5aa289ade2d8316ac531ebdeee23f6 Mon Sep 17 00:00:00 2001
From: junjun
Date: Wed, 27 Mar 2019 14:41:03 +0800
Subject: [PATCH 15/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index a417f80a61..1b5bcb0bda 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -22,7 +22,7 @@ permalink: docs/error-boundaries.html
> * 服务端渲染
> * 它自身抛出来的错误(并非它的子组件)
-如果一个类组件中定义了 [`static getDerivedStateFromError()`](/docs/react-component.html#static-getderivedstatefromerror) 或 [`componentDidCatch()`](/docs/react-component.html#componentdidcatch) 这两个生命周期方法中的任意一个(或两个)时,那么它就变成一个错误边界 (error boundary)。当抛出错误后,请使用使用 `static getDerivedStateFromError()` 渲染备用 UI ,使用 `componentDidCatch()` 记录错误信息。
+如果一个 class 组件中定义了 [`static getDerivedStateFromError()`](/docs/react-component.html#static-getderivedstatefromerror) 或 [`componentDidCatch()`](/docs/react-component.html#componentdidcatch) 这两个生命周期方法中的任意一个(或两个)时,那么它就变成一个错误边界 (error boundary)。当抛出错误后,请使用使用 `static getDerivedStateFromError()` 渲染备用 UI ,使用 `componentDidCatch()` 记录错误信息。
```js{7-10,12-15,18-21}
class ErrorBoundary extends React.Component {
From 42a10462a86be432045623fbc246b36ba882ab74 Mon Sep 17 00:00:00 2001
From: Yuqing Chen
Date: Fri, 12 Apr 2019 09:51:09 +0800
Subject: [PATCH 16/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 1b5bcb0bda..74f804c935 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -15,7 +15,7 @@ permalink: docs/error-boundaries.html
> 注意
>
-> 错误边界 **无法** 捕获以下场景中产生的错误:
+> 错误边界**无法**捕获以下场景中产生的错误:
>
> * 事件处理([了解更多](#how-about-event-handlers))
> * 异步代码(例如 `setTimeout` 或 `requestAnimationFrame` 回调函数)
From 4f0d367286af922fe77f8db92c8af8fc5e453e11 Mon Sep 17 00:00:00 2001
From: Yuqing Chen
Date: Fri, 12 Apr 2019 09:51:54 +0800
Subject: [PATCH 17/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 74f804c935..d262314e52 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -22,7 +22,7 @@ permalink: docs/error-boundaries.html
> * 服务端渲染
> * 它自身抛出来的错误(并非它的子组件)
-如果一个 class 组件中定义了 [`static getDerivedStateFromError()`](/docs/react-component.html#static-getderivedstatefromerror) 或 [`componentDidCatch()`](/docs/react-component.html#componentdidcatch) 这两个生命周期方法中的任意一个(或两个)时,那么它就变成一个错误边界 (error boundary)。当抛出错误后,请使用使用 `static getDerivedStateFromError()` 渲染备用 UI ,使用 `componentDidCatch()` 记录错误信息。
+如果一个 class 组件中定义了 [`static getDerivedStateFromError()`](/docs/react-component.html#static-getderivedstatefromerror) 或 [`componentDidCatch()`](/docs/react-component.html#componentdidcatch) 这两个生命周期方法中的任意一个(或两个)时,那么它就变成一个错误边界 (error boundary)。当抛出错误后,请使用 `static getDerivedStateFromError()` 渲染备用 UI ,使用 `componentDidCatch()` 打印错误信息。
```js{7-10,12-15,18-21}
class ErrorBoundary extends React.Component {
From 2b2286e5d32edb093cf7a5f44de7e9bf2da302de Mon Sep 17 00:00:00 2001
From: Yuqing Chen
Date: Fri, 12 Apr 2019 09:55:48 +0800
Subject: [PATCH 18/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index d262314e52..eb8dad7976 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -62,7 +62,7 @@ class ErrorBoundary extends React.Component {
错误边界的工作方式类似于 JavaScript `catch {}`,不同的地方在于错误边界只针对 React 组件。只有 class 组件可以通过实现指定的方法变成错误边界组件,实际上大多数情况下, 您需要声明一次错误边界组件, 并在整个应用程序中使用它。
-注意 **错误边界仅可以捕获其子组件的错误** ,它无法捕获其自身的错误。如果一个错误边界无法渲染错误信息,则错误会采用就近原则,冒泡至最接近的错误边界,这也类似于 JavaScript 中 catch {} 的工作机制。
+注意**错误边界仅可以捕获其子组件的错误**,它无法捕获其自身的错误。如果一个错误边界无法渲染错误信息,则错误会冒泡至最近的上层错误边界,这也类似于 JavaScript 中 catch {} 的工作机制。
## 在线演示 {#live-demo}
From 53b869f35a1e97efafefa0d7cb94b0069d82ebdb Mon Sep 17 00:00:00 2001
From: Yuqing Chen
Date: Fri, 12 Apr 2019 09:56:15 +0800
Subject: [PATCH 19/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index eb8dad7976..3dbb17b6a9 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -66,7 +66,7 @@ class ErrorBoundary extends React.Component {
## 在线演示 {#live-demo}
-查看通过 [React 16](/blog/2017/09/26/react-v16.0.html) [定义和使用错误边界的例子](/blog/2017/09/26/react-v16.0.html)。
+查看使用 [React 16](/blog/2017/09/26/react-v16.0.html) [定义和使用错误边界的例子](/blog/2017/09/26/react-v16.0.html)。
## 错误边界应该放置在哪? {#where-to-place-error-boundaries}
From 1021f9512c80e7f9bf879b232ee7049597115210 Mon Sep 17 00:00:00 2001
From: Yuqing Chen
Date: Fri, 12 Apr 2019 09:59:19 +0800
Subject: [PATCH 20/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 3dbb17b6a9..65c4b3f590 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -78,7 +78,7 @@ class ErrorBoundary extends React.Component {
这一改变具有重要意义,**自 React 16 起,任何未被错误边界捕获的错误将会导致整个 React 组件树被卸载。**
-React 开发团队内部对这一决定有过一些争论,但在我们的经验中放置一个错误的 UI 比完全移除它要更糟糕。例如,在类似 Messenger 的产品中让一个异常的 UI 对用户可见可能会导致用户将信息错发给别人。同样,对于支付类应用而言,显示错误的金额也比不呈现任何内容更糟糕。
+我们对这一决定有过一些争论,但根据我们的经验,把一个错误的 UI 留在那比完全移除它要更糟糕。例如,在类似 Messenger 的产品中,把一个异常的 UI 展示给用户可能会导致用户将信息错发给别人。同样,对于支付类应用而言,显示错误的金额也比不呈现任何内容更糟糕。
此变化意味着当你迁入到 React 16 时,你可能会发现一些已存在你应用中但未曾注意到的崩溃。增加错误边界能够让你在应用发生异常时提供更好的用户体验。
From ef754ffe0400e3de776e78c149b6e4147936dee1 Mon Sep 17 00:00:00 2001
From: Yuqing Chen
Date: Fri, 12 Apr 2019 09:59:54 +0800
Subject: [PATCH 21/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 65c4b3f590..1fdf544bd5 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -80,7 +80,7 @@ class ErrorBoundary extends React.Component {
我们对这一决定有过一些争论,但根据我们的经验,把一个错误的 UI 留在那比完全移除它要更糟糕。例如,在类似 Messenger 的产品中,把一个异常的 UI 展示给用户可能会导致用户将信息错发给别人。同样,对于支付类应用而言,显示错误的金额也比不呈现任何内容更糟糕。
-此变化意味着当你迁入到 React 16 时,你可能会发现一些已存在你应用中但未曾注意到的崩溃。增加错误边界能够让你在应用发生异常时提供更好的用户体验。
+此变化意味着当你迁移到 React 16 时,你可能会发现一些已存在你应用中但未曾注意到的崩溃。增加错误边界能够让你在应用发生异常时提供更好的用户体验。
例如,Facebook Messenger 将侧边栏、信息面板、对话框以及信息输入框包装在单独的错误边界中。如果其中的某些 UI 组件崩溃,其余部分仍然能够交互。
From cc8680755114f51803825246d4e3dd294bc3072c Mon Sep 17 00:00:00 2001
From: Yuqing Chen
Date: Fri, 12 Apr 2019 10:00:07 +0800
Subject: [PATCH 22/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 1fdf544bd5..f4132aa1f0 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -126,7 +126,7 @@ try {
## 关于事件处理器 {#how-about-event-handlers}
-错误边界 **无法** 捕获事件处理器内部的错误。
+错误边界**无法**捕获事件处理器内部的错误。
React 不需要错误边界来从事件处理程序的错误中恢复。与渲染方法和生命周期钩子不同,事件处理器不会在渲染期间触发。因此,如果它们抛出异常,React 仍然能够知道需要在屏幕上显示什么。
From a98f307ed4f1257ffdabc57cd6b6bf1359e27b1f Mon Sep 17 00:00:00 2001
From: Yuqing Chen
Date: Fri, 12 Apr 2019 10:01:13 +0800
Subject: [PATCH 23/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index f4132aa1f0..0b7642f7cb 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -82,7 +82,7 @@ class ErrorBoundary extends React.Component {
此变化意味着当你迁移到 React 16 时,你可能会发现一些已存在你应用中但未曾注意到的崩溃。增加错误边界能够让你在应用发生异常时提供更好的用户体验。
-例如,Facebook Messenger 将侧边栏、信息面板、对话框以及信息输入框包装在单独的错误边界中。如果其中的某些 UI 组件崩溃,其余部分仍然能够交互。
+例如,Facebook Messenger 将侧边栏、信息面板、聊天记录以及信息输入框包装在单独的错误边界中。如果其中的某些 UI 组件崩溃,其余部分仍然能够交互。
我们也鼓励使用 JS 错误报告服务(或自行构建),这样你能了解关于生产环境中出现的未捕获异常,并将其修复。
From b3445ae0827bcb50c36bb82961a190c6e197a444 Mon Sep 17 00:00:00 2001
From: Yuqing Chen
Date: Fri, 12 Apr 2019 10:01:46 +0800
Subject: [PATCH 24/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 0b7642f7cb..03a0d496f2 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -89,7 +89,7 @@ class ErrorBoundary extends React.Component {
## 组件栈追踪 {#component-stack-traces}
-React 16 会在渲染期间将所有在开发环境下抛出的错误打印到控制台,即使应用程序意外的将其掩盖。除了错误信息和 JavaScript 栈外,React 16 还提供了组件栈追踪。现在你可以准确地查看发生在组件树内的错误信息:
+在开发环境下,React 16 会把渲染期间发生的错误打印到控制台,即使该应用意外的将这些错误掩盖。除了错误信息和 JavaScript 栈外,React 16 还提供了组件栈追踪。现在你可以准确地查看发生在组件树内的错误信息:
From 3fa6ef5377658f330513b6692b3be5b0f3e2f539 Mon Sep 17 00:00:00 2001
From: Yuqing Chen
Date: Fri, 12 Apr 2019 10:02:20 +0800
Subject: [PATCH 25/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 03a0d496f2..7b5b7cc5f1 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -97,7 +97,7 @@ class ErrorBoundary extends React.Component {
-如果你没有使用 Create React App ,可以手动将[该插件](https://www.npmjs.com/package/babel-plugin-transform-react-jsx-source)添加到你的 Babel 配置中。注意它仅可在开发环境下使用,而 **生产环境必须将其禁用** 。
+如果你没有使用 Create React App,可以手动将[该插件](https://www.npmjs.com/package/babel-plugin-transform-react-jsx-source)添加到你的 Babel 配置中。注意它仅用于开发环境,**在生产环境必须将其禁用** 。
> 注意
>
From 376b9a3100cd022fb409b8269beada1b6b873815 Mon Sep 17 00:00:00 2001
From: Yuqing Chen
Date: Fri, 12 Apr 2019 10:02:46 +0800
Subject: [PATCH 26/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 7b5b7cc5f1..d09c535574 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -122,7 +122,7 @@ try {
```
-错误边界保留了 React 的声明性质,其行为符合你的预期。例如,即使一个错误发生在 `componentDidUpdate` 方法中,由某一个深层组件树的 `setState` 引起,其仍然能够冒泡到最近的错误边界。
+错误边界保留了 React 的声明性质,其行为符合你的预期。例如,即使一个错误发生在 `componentDidUpdate` 方法中,并且由某一个深层组件树的 `setState` 引起,其仍然能够冒泡到最近的错误边界。
## 关于事件处理器 {#how-about-event-handlers}
From a602b30fff4fc38cf69ba0ddea0acbcbd03742db Mon Sep 17 00:00:00 2001
From: Yuqing Chen
Date: Fri, 12 Apr 2019 10:03:18 +0800
Subject: [PATCH 27/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index d09c535574..c2fc1ee21e 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -128,7 +128,7 @@ try {
错误边界**无法**捕获事件处理器内部的错误。
-React 不需要错误边界来从事件处理程序的错误中恢复。与渲染方法和生命周期钩子不同,事件处理器不会在渲染期间触发。因此,如果它们抛出异常,React 仍然能够知道需要在屏幕上显示什么。
+React 不需要错误边界来从事件处理程序的错误中恢复。与 render 方法和生命周期方法不同,事件处理器不会在渲染期间触发。因此,如果它们抛出异常,React 仍然能够知道需要在屏幕上显示什么。
如果你需要在事件处理器内部捕获错误,使用普通的 JavaScript `try` / `catch` 语句:
From 57eb16d5d6c03b93780444e2c73cbb1901b8be3a Mon Sep 17 00:00:00 2001
From: QC-L
Date: Mon, 15 Apr 2019 10:30:07 +0800
Subject: [PATCH 28/36] docs(cn): fix nav.yml
---
content/docs/nav.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/nav.yml b/content/docs/nav.yml
index 8b95ec1ed4..57e442d976 100644
--- a/content/docs/nav.yml
+++ b/content/docs/nav.yml
@@ -44,7 +44,7 @@
- id: context
title: Context
- id: error-boundaries
- title: 异常捕获边界
+ title: 错误边界
- id: forwarding-refs
title: Refs 转发
- id: fragments
From 45519d8787ead8f703a6431ab6ef08d5cc2f591b Mon Sep 17 00:00:00 2001
From: QiChang Li
Date: Mon, 15 Apr 2019 10:36:07 +0800
Subject: [PATCH 29/36] Update error-boundaries.md
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index c2fc1ee21e..3315458033 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -1,6 +1,6 @@
---
id: error-boundaries
-title: Error Boundaries
+title: 错误边界
permalink: docs/error-boundaries.html
---
From 7bd65c294052ef23d34b90258cfd22698166e039 Mon Sep 17 00:00:00 2001
From: Yuqing Chen
Date: Sat, 20 Apr 2019 20:51:09 +0800
Subject: [PATCH 30/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 3315458033..e65b2d58d5 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -60,7 +60,7 @@ class ErrorBoundary extends React.Component {
```
-错误边界的工作方式类似于 JavaScript `catch {}`,不同的地方在于错误边界只针对 React 组件。只有 class 组件可以通过实现指定的方法变成错误边界组件,实际上大多数情况下, 您需要声明一次错误边界组件, 并在整个应用程序中使用它。
+错误边界的工作方式类似于 JavaScript 的 `catch {}`,不同的地方在于错误边界只针对 React 组件。只有 class 组件才可以成为成错误边界组件。大多数情况下, 你只需要声明一次错误边界组件, 并在整个应用中使用它。
注意**错误边界仅可以捕获其子组件的错误**,它无法捕获其自身的错误。如果一个错误边界无法渲染错误信息,则错误会冒泡至最近的上层错误边界,这也类似于 JavaScript 中 catch {} 的工作机制。
From 76b5e0d72147113d6e055fae5bdc89626c0f3678 Mon Sep 17 00:00:00 2001
From: Lcina
Date: Sat, 20 Apr 2019 20:54:28 +0800
Subject: [PATCH 31/36] Update error-boundaries.md
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index e65b2d58d5..fa20725b1e 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -22,7 +22,7 @@ permalink: docs/error-boundaries.html
> * 服务端渲染
> * 它自身抛出来的错误(并非它的子组件)
-如果一个 class 组件中定义了 [`static getDerivedStateFromError()`](/docs/react-component.html#static-getderivedstatefromerror) 或 [`componentDidCatch()`](/docs/react-component.html#componentdidcatch) 这两个生命周期方法中的任意一个(或两个)时,那么它就变成一个错误边界 (error boundary)。当抛出错误后,请使用 `static getDerivedStateFromError()` 渲染备用 UI ,使用 `componentDidCatch()` 打印错误信息。
+如果一个 class 组件中定义了 [`static getDerivedStateFromError()`](/docs/react-component.html#static-getderivedstatefromerror) 或 [`componentDidCatch()`](/docs/react-component.html#componentdidcatch) 这两个生命周期方法中的任意一个(或两个)时,那么它就变成一个错误边界。当抛出错误后,请使用 `static getDerivedStateFromError()` 渲染备用 UI ,使用 `componentDidCatch()` 打印错误信息。
```js{7-10,12-15,18-21}
class ErrorBoundary extends React.Component {
From 8664ea0fb5f5d60a534c4594da571ba4d5b80ec9 Mon Sep 17 00:00:00 2001
From: Alan Zhang
Date: Sat, 20 Apr 2019 20:56:16 +0800
Subject: [PATCH 32/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index fa20725b1e..5220a22006 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -89,7 +89,7 @@ class ErrorBoundary extends React.Component {
## 组件栈追踪 {#component-stack-traces}
-在开发环境下,React 16 会把渲染期间发生的错误打印到控制台,即使该应用意外的将这些错误掩盖。除了错误信息和 JavaScript 栈外,React 16 还提供了组件栈追踪。现在你可以准确地查看发生在组件树内的错误信息:
+在开发环境下,React 16 会把渲染期间发生的所有错误打印到控制台,即使该应用意外的将这些错误掩盖。除了错误信息和 JavaScript 栈外,React 16 还提供了组件栈追踪。现在你可以准确地查看发生在组件树内的错误信息:
From bf9fb8aba11b749e0f0b97390a34c19da386904f Mon Sep 17 00:00:00 2001
From: Lcina
Date: Sat, 20 Apr 2019 20:58:17 +0800
Subject: [PATCH 33/36] Update error-boundaries.md
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 5220a22006..8440374089 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -161,6 +161,6 @@ class MyComponent extends React.Component {
## 自 React 15 的命名更改 {#naming-changes-from-react-15}
-React 15 在一个不同的方法名下:`unstable_handleError` 包含了一个支持有限的错误边界。此方法不再起作用,同时自 React 16 beta 发布起你需要在代码中将其修改为 `componentDidCatch` 。
+React 15 中有一个支持有限的错误边界方法 `unstable_handleError`。此方法不再起作用,同时自 React 16 beta 发布起你需要在代码中将其修改为 `componentDidCatch` 。
对此,我们已提供了一个 [codemod](https://github.com/reactjs/react-codemod#error-boundaries) 来帮助你自动迁移你的代码。
From 673c4338b4513574cb429b3d1b1765744cefac5b Mon Sep 17 00:00:00 2001
From: Lcina
Date: Sat, 20 Apr 2019 21:02:53 +0800
Subject: [PATCH 34/36] Update error-boundaries.md
---
content/docs/error-boundaries.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 8440374089..0313d437ff 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -10,8 +10,8 @@ permalink: docs/error-boundaries.html
## 错误边界(Error Boundaries) {#introducing-error-boundaries}
部分 UI 的 JavaScript 错误不应该导致整个应用崩溃,为了解决这个问题,React 16 引入了一个新的概念 —— 错误边界。
-
-错误边界并不会使整个组件树崩溃,它是 **用于捕获子组件树中任意位置的 JavaScript 错误,记录错误并显示一个备用 UI** 的 React 组件。 错误边界在渲染期间、生命周期方法和整个组件树的构造函数中捕获错误。
+
+错误边界是一种 React 组件,这种组件**可以捕获并打印发生在其子组件树任何位置的 JavaScript 错误,并且,它会渲染出备用 UI**,而不是渲染那些崩溃了的子组件树。错误边界在渲染期间、生命周期方法和整个组件树的构造函数中捕获错误。
> 注意
>
From ae13c1a9c93ebd6a325c14045b9534dc3e1069e5 Mon Sep 17 00:00:00 2001
From: QiChang Li
Date: Sat, 20 Apr 2019 21:17:24 +0800
Subject: [PATCH 35/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index 0313d437ff..fe81fc0185 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -4,7 +4,7 @@ title: 错误边界
permalink: docs/error-boundaries.html
---
-过去,组件内的 JavaScript 错误会导致 React 的内部状态被破坏,并且在下一次渲染时 [产生](https://github.com/facebook/react/issues/4026) [可能无法追踪的](https://github.com/facebook/react/issues/6895) [错误](https://github.com/facebook/react/issues/8579)。这些错误基本上是由较早的其他代码(非React组件代码)错误引起的,但 React 并没有提供一种在组件中优雅处理这些错误的方式,也无法从错误中恢复。
+过去,组件内的 JavaScript 错误会导致 React 的内部状态被破坏,并且在下一次渲染时 [产生](https://github.com/facebook/react/issues/4026) [可能无法追踪的](https://github.com/facebook/react/issues/6895) [错误](https://github.com/facebook/react/issues/8579)。这些错误基本上是由较早的其他代码(非 React 组件代码)错误引起的,但 React 并没有提供一种在组件中优雅处理这些错误的方式,也无法从错误中恢复。
## 错误边界(Error Boundaries) {#introducing-error-boundaries}
From 0d59fa3cbf56ff1e70bf23620b3c267553463643 Mon Sep 17 00:00:00 2001
From: QiChang Li
Date: Sat, 20 Apr 2019 21:17:41 +0800
Subject: [PATCH 36/36] Update content/docs/error-boundaries.md
Co-Authored-By: LCINA <870206584@qq.com>
---
content/docs/error-boundaries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md
index fe81fc0185..356cf0e739 100644
--- a/content/docs/error-boundaries.md
+++ b/content/docs/error-boundaries.md
@@ -161,6 +161,6 @@ class MyComponent extends React.Component {
## 自 React 15 的命名更改 {#naming-changes-from-react-15}
-React 15 中有一个支持有限的错误边界方法 `unstable_handleError`。此方法不再起作用,同时自 React 16 beta 发布起你需要在代码中将其修改为 `componentDidCatch` 。
+React 15 中有一个支持有限的错误边界方法 `unstable_handleError`。此方法不再起作用,同时自 React 16 beta 发布起你需要在代码中将其修改为 `componentDidCatch`。
对此,我们已提供了一个 [codemod](https://github.com/reactjs/react-codemod#error-boundaries) 来帮助你自动迁移你的代码。