reactjs / reactjs/react.dev

Order of life cycle method calls with error boundaries is unexpected

オープン
#1,031 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
JavaScript
スター
11.8k
フォーク
7.9k
平均マージ
1日 11時間
マージ済み PR(30日)
11

説明

I have a requirement for my app to track when a component has completed rendering and whether the render ended in success or failure. I expected to be able to use the componentDidMount/componentDidUpdate life cycle methods along with an error boundary's componentDidCatch method to handle both success and failure cases.

However, I am noticing that the order of the life cycle methods is not what I expect. When an exception is raised within a child component in the error boundary, the component's componentDidMount/componentDidUpdate method will get called first before componentDidCatch. So I can't simply use componentDidMount/componentDidUpdate to determine that my scenario ended in success.

Is this a bug? How would I go about achieving this scenario?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

ファイル、テスト、エントリーポイントは指定されていません。まず、componentDidMount、componentDidUpdate、componentDidCatch、error boundaries を扱っている React のドキュメントを見つけ、報告されているライフサイクルの順序を検証してください。期待される動作と、レンダリングの成功と失敗を区別するためのサポートされた方法が明確に文書化されていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, react
領域
documentation
issue の種類
ドキュメント
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。