Skip to content

Commit 44a9be3

Browse files
docs: translate captureOwnerStack.md to Русский
1 parent 2958f53 commit 44a9be3

1 file changed

Lines changed: 46 additions & 46 deletions

File tree

src/content/reference/react/captureOwnerStack.md

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: captureOwnerStack
44

55
<Intro>
66

7-
`captureOwnerStack` reads the current Owner Stack in development and returns it as a string if available.
7+
`captureOwnerStack` считывает текущий стек владельца (Owner Stack) в режиме разработки и возвращает его в виде строки, если он доступен.
88

99
```js
1010
const stack = captureOwnerStack();
@@ -16,11 +16,11 @@ const stack = captureOwnerStack();
1616

1717
---
1818

19-
## Reference {/*reference*/}
19+
## Справочник {/*reference*/}
2020

2121
### `captureOwnerStack()` {/*captureownerstack*/}
2222

23-
Call `captureOwnerStack` to get the current Owner Stack.
23+
Вызовите `captureOwnerStack`, чтобы получить текущий стек владельца.
2424

2525
```js {5,5}
2626
import * as React from 'react';
@@ -33,33 +33,33 @@ function Component() {
3333
}
3434
```
3535

36-
#### Parameters {/*parameters*/}
36+
#### Параметры {/*parameters*/}
3737

38-
`captureOwnerStack` does not take any parameters.
38+
`captureOwnerStack` не принимает никаких параметров.
3939

40-
#### Returns {/*returns*/}
40+
#### Возвращаемое значение {/*returns*/}
4141

42-
`captureOwnerStack` returns `string | null`.
42+
`captureOwnerStack` возвращает `string | null`.
4343

44-
Owner Stacks are available in
45-
- Component render
46-
- Effects (e.g. `useEffect`)
47-
- React's event handlers (e.g. `<button onClick={...} />`)
48-
- React error handlers ([React Root options](/reference/react-dom/client/createRoot#parameters) `onCaughtError`, `onRecoverableError`, and `onUncaughtError`)
44+
Стеки владельца доступны в:
45+
- Рендере компонента
46+
- Эффектах (например, `useEffect`)
47+
- Обработчиках событий React (например, `<button onClick={...} />`)
48+
- Обработчиках ошибок React ([Параметры React Root](/reference/react-dom/client/createRoot#parameters) `onCaughtError`, `onRecoverableError` и `onUncaughtError`)
4949

50-
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)).
5151

52-
#### Caveats {/*caveats*/}
52+
#### Ограничения {/*caveats*/}
5353

54-
- Owner Stacks are only available in development. `captureOwnerStack` will always return `null` outside of development.
54+
- Стеки владельца доступны только в режиме разработки. `captureOwnerStack` всегда будет возвращать `null` вне режима разработки.
5555

5656
<DeepDive>
5757

58-
#### Owner Stack vs Component Stack {/*owner-stack-vs-component-stack*/}
58+
#### Стек владельца против стека компонентов {/*owner-stack-vs-component-stack*/}
5959

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).
6161

62-
For example, consider the following code:
62+
Рассмотрим следующий код:
6363

6464
<Sandpack>
6565

@@ -105,11 +105,11 @@ import './styles.css';
105105

106106
createRoot(document.createElement('div'), {
107107
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 в реальной консоли.
113113
console.log(errorInfo.componentStack);
114114
console.log(captureOwnerStack());
115115
},
@@ -136,8 +136,8 @@ createRoot(document.createElement('div'), {
136136

137137
</Sandpack>
138138

139-
`SubComponent` would throw an error.
140-
The Component Stack of that error would be
139+
`SubComponent` вызовет ошибку.
140+
Стек компонентов этой ошибки будет выглядеть так:
141141

142142
```
143143
at SubComponent
@@ -148,23 +148,23 @@ at React.Suspense
148148
at App
149149
```
150150

151-
However, the Owner Stack would only read
151+
Однако стек владельца будет содержать только:
152152

153153
```
154154
at Component
155155
```
156156

157-
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 />`.
158158

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 />`.
160160

161-
`SubComponent` is omitted because it's already part of the callstack.
161+
`SubComponent` опущен, потому что он уже является частью стека вызовов.
162162

163163
</DeepDive>
164164

165-
## Usage {/*usage*/}
165+
## Использование {/*usage*/}
166166

167-
### Enhance a custom error overlay {/*enhance-a-custom-error-overlay*/}
167+
### Улучшение пользовательского оверлея ошибок {/*enhance-a-custom-error-overlay*/}
168168

169169
```js [[1, 5, "console.error"], [4, 7, "captureOwnerStack"]]
170170
import { captureOwnerStack } from "react";
@@ -175,15 +175,15 @@ console.error = function patchedConsoleError(...args) {
175175
originalConsoleError.apply(console, args);
176176
const ownerStack = captureOwnerStack();
177177
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+
// вызван с несколькими аргументами, которые следует учитывать.
180180
consoleMessage: args[0],
181181
ownerStack,
182182
});
183183
};
184184
```
185185

186-
If you intercept <CodeStep step={1}>`console.error`</CodeStep> calls to highlight them in an error overlay, you can call <CodeStep step={2}>`captureOwnerStack`</CodeStep> to include the Owner Stack.
186+
Если вы перехватываете вызовы <CodeStep step={1}>`console.error`</CodeStep>, чтобы отобразить их в оверлее ошибок, вы можете вызвать <CodeStep step={2}>`captureOwnerStack`</CodeStep>, чтобы включить стек владельца.
187187

188188
<Sandpack>
189189

@@ -347,24 +347,24 @@ export default function App() {
347347

348348
</Sandpack>
349349

350-
## Troubleshooting {/*troubleshooting*/}
350+
## Устранение неполадок {/*troubleshooting*/}
351351

352-
### The Owner Stack is `null` {/*the-owner-stack-is-null*/}
352+
### Стек владельца равен `null` {/*the-owner-stack-is-null*/}
353353

354-
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`) стеки владельца должны быть доступны.
355355

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` в тело эффекта.
357357
<Sandpack>
358358

359359
```js
360360
import {captureOwnerStack, useEffect} from 'react';
361361

362362
export default function App() {
363363
useEffect(() => {
364-
// Should call `captureOwnerStack` here.
364+
// Следует вызвать `captureOwnerStack` здесь.
365365
function handleEvent() {
366-
// Calling it in a custom DOM event handler is too late.
367-
// The Owner Stack will be `null` at this point.
366+
// Вызов в пользовательском обработчике событий DOM — это слишком поздно.
367+
// Стек владельца в этот момент будет равен `null`.
368368
console.log('Owner Stack: ', captureOwnerStack());
369369
}
370370

@@ -381,18 +381,18 @@ export default function App() {
381381

382382
</Sandpack>
383383

384-
### `captureOwnerStack` is not available {/*captureownerstack-is-not-available*/}
384+
### `captureOwnerStack` недоступен {/*captureownerstack-is-not-available*/}
385385

386-
`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` используется в файлах, которые собираются как для продакшена, так и для разработки, следует получать к нему доступ условно из импорта пространства имен.
387387

388388
```js
389-
// Don't use named imports of `captureOwnerStack` in files that are bundled for development and production.
389+
// Не используйте именованные импорты `captureOwnerStack` в файлах, которые собираются для разработки и продакшена.
390390
import {captureOwnerStack} from 'react';
391-
// Use a namespace import instead and access `captureOwnerStack` conditionally.
391+
// Вместо этого используйте импорт пространства имен и обращайтесь к `captureOwnerStack` условно.
392392
import * as React from 'react';
393393

394394
if (process.env.NODE_ENV !== 'production') {
395395
const ownerStack = React.captureOwnerStack();
396396
console.log('Owner Stack', ownerStack);
397397
}
398-
```
398+
```

0 commit comments

Comments
 (0)