You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If no Owner Stack is available, `null`is returned (see [Troubleshooting: The Owner Stack is`null`](#the-owner-stack-is-null)).
50
+
Если стек владельца недоступен, возвращается `null`(см. [Устранение неполадок: Стек владельца равен`null`](#the-owner-stack-is-null)).
51
51
52
-
#### Caveats {/*caveats*/}
52
+
#### Ограничения {/*caveats*/}
53
53
54
-
-Owner Stacks are only available in development. `captureOwnerStack`will always return`null`outside of development.
54
+
-Стеки владельца доступны только в режиме разработки. `captureOwnerStack`всегда будет возвращать`null`вне режима разработки.
55
55
56
56
<DeepDive>
57
57
58
-
#### Owner Stack vs Component Stack {/*owner-stack-vs-component-stack*/}
58
+
#### Стек владельца против стека компонентов {/*owner-stack-vs-component-stack*/}
59
59
60
-
The Owner Stack is different from the Component Stack available in React error handlers like [`errorInfo.componentStack`in`onUncaughtError`](/reference/react-dom/client/hydrateRoot#show-a-dialog-for-uncaught-errors).
60
+
Стек владельца отличается от стека компонентов, доступного в обработчиках ошибок React, таких как [`errorInfo.componentStack`в`onUncaughtError`](/reference/react-dom/client/hydrateRoot#show-a-dialog-for-uncaught-errors).
61
61
62
-
For example, consider the following code:
62
+
Рассмотрим следующий код:
63
63
64
64
<Sandpack>
65
65
@@ -105,11 +105,11 @@ import './styles.css';
105
105
106
106
createRoot(document.createElement('div'), {
107
107
onUncaughtError: (error, errorInfo) => {
108
-
//The stacks are logged instead of showing them in the UI directly to
109
-
//highlight that browsers will apply sourcemaps to the logged stacks.
110
-
//Note that sourcemapping is only applied in the real browser console not
111
-
//in the fake one displayed on this page.
112
-
//Press "fork" to be able to view the sourcemapped stack in a real console.
108
+
//Стеки выводятся в лог вместо прямого отображения в UI, чтобы
109
+
//подчеркнуть, что браузеры применяют sourcemaps к выведенным стекам.
110
+
//Обратите внимание, что sourcemapping применяется только в реальной консоли браузера, а не
111
+
//в поддельной, отображаемой на этой странице.
112
+
//Нажмите "fork", чтобы иметь возможность просмотреть стек с примененным sourcemapping в реальной консоли.
Neither`App` nor the DOM components (e.g.`fieldset`) are considered Owners in this Stack since they didn't contribute to "creating" the node containing `SubComponent`. `App`and DOM components only forwarded the node. `App`just rendered the`children` node as opposed to `Component` which created a node containing `SubComponent` via`<SubComponent />`.
157
+
Ни`App`, ни DOM-компоненты (например,`fieldset`) не считаются владельцами в этом стеке, поскольку они не участвовали в «создании» узла, содержащего `SubComponent`. `App`и DOM-компоненты только перенаправляли узел. `App`просто отрендерил узел`children`, в отличие от `Component`, который создал узел, содержащий `SubComponent`, через`<SubComponent />`.
158
158
159
-
Neither`Navigation` nor`legend`are in the stack at all since it's only a sibling to a node containing`<SubComponent />`.
159
+
Ни`Navigation`, ни`legend`вообще не присутствуют в стеке, поскольку они являются лишь соседями узла, содержащего`<SubComponent />`.
160
160
161
-
`SubComponent`is omitted because it's already part of the callstack.
161
+
`SubComponent`опущен, потому что он уже является частью стека вызовов.
162
162
163
163
</DeepDive>
164
164
165
-
## Usage {/*usage*/}
165
+
## Использование {/*usage*/}
166
166
167
-
### Enhance a custom error overlay {/*enhance-a-custom-error-overlay*/}
@@ -175,15 +175,15 @@ console.error = function patchedConsoleError(...args) {
175
175
originalConsoleError.apply(console, args);
176
176
constownerStack=captureOwnerStack();
177
177
onConsoleError({
178
-
//Keep in mind that in a real application, console.error can be
179
-
//called with multiple arguments which you should account for.
178
+
//Имейте в виду, что в реальном приложении console.error может быть
179
+
//вызван с несколькими аргументами, которые следует учитывать.
180
180
consoleMessage: args[0],
181
181
ownerStack,
182
182
});
183
183
};
184
184
```
185
185
186
-
If you intercept <CodeStepstep={1}>`console.error`</CodeStep> calls to highlight them in an error overlay, you can call <CodeStepstep={2}>`captureOwnerStack`</CodeStep> to include the Owner Stack.
186
+
Если вы перехватываете вызовы <CodeStepstep={1}>`console.error`</CodeStep>, чтобы отобразить их в оверлее ошибок, вы можете вызвать <CodeStepstep={2}>`captureOwnerStack`</CodeStep>, чтобы включить стек владельца.
187
187
188
188
<Sandpack>
189
189
@@ -347,24 +347,24 @@ export default function App() {
347
347
348
348
</Sandpack>
349
349
350
-
## Troubleshooting {/*troubleshooting*/}
350
+
## Устранение неполадок {/*troubleshooting*/}
351
351
352
-
### The Owner Stack is`null` {/*the-owner-stack-is-null*/}
The call of `captureOwnerStack`happened outside of a React controlled function e.g. in a `setTimeout` callback, after a`fetch`call or in a custom DOM event handler. During render, Effects, React event handlers, and React error handlers (e.g.`hydrateRoot#options.onCaughtError`) Owner Stacks should be available.
354
+
Вызов `captureOwnerStack`произошел вне функции, управляемой React, например, в колбэке `setTimeout`, после вызова`fetch`или в пользовательском обработчике событий DOM. Во время рендеринга, эффектов, обработчиков событий React и обработчиков ошибок React (например,`hydrateRoot#options.onCaughtError`) стеки владельца должны быть доступны.
355
355
356
-
In the example below, clicking the button will log an empty Owner Stack because`captureOwnerStack`was called during a custom DOM event handler. The Owner Stack must be captured earlier e.g. by moving the call of `captureOwnerStack`into the Effect body.
356
+
В приведенном ниже примере нажатие на кнопку приведет к выводу пустого стека владельца, поскольку`captureOwnerStack`был вызван во время пользовательского обработчика событий DOM. Стек владельца должен быть захвачен раньше, например, путем перемещения вызова `captureOwnerStack`в тело эффекта.
`captureOwnerStack`is only exported in development builds. It will be `undefined` in production builds. If`captureOwnerStack`is used in files that are bundled for production and development, you should conditionally access it from a namespace import.
386
+
`captureOwnerStack`экспортируется только в сборках для разработки. В продакшен-сборках он будет `undefined`. Если`captureOwnerStack`используется в файлах, которые собираются как для продакшена, так и для разработки, следует получать к нему доступ условно из импорта пространства имен.
387
387
388
388
```js
389
-
//Don't use named imports of `captureOwnerStack` in files that are bundled for development and production.
389
+
//Не используйте именованные импорты `captureOwnerStack` в файлах, которые собираются для разработки и продакшена.
390
390
import {captureOwnerStack} from'react';
391
-
//Use a namespace import instead and access `captureOwnerStack` conditionally.
391
+
//Вместо этого используйте импорт пространства имен и обращайтесь к `captureOwnerStack` условно.
0 commit comments