MCPcopy
hub / github.com/react/react / initializeClassErrorUpdate

Function initializeClassErrorUpdate

packages/react-reconciler/src/ReactFiberThrow.js:118–199  ·  view source on GitHub ↗
(
  update: Update<mixed>,
  root: FiberRoot,
  fiber: Fiber,
  errorInfo: CapturedValue<mixed>,
)

Source from the content-addressed store, hash-verified

116}
117
118function initializeClassErrorUpdate(
119 update: Update<mixed>,
120 root: FiberRoot,
121 fiber: Fiber,
122 errorInfo: CapturedValue<mixed>,
123): void {
124 const getDerivedStateFromError = fiber.type.getDerivedStateFromError;
125 if (typeof getDerivedStateFromError === 'function') {
126 const error = errorInfo.value;
127 update.payload = () => {
128 return getDerivedStateFromError(error);
129 };
130 update.callback = () => {
131 if (__DEV__) {
132 markFailedErrorBoundaryForHotReloading(fiber);
133 }
134 if (__DEV__) {
135 runWithFiberInDEV(
136 errorInfo.source,
137 logCaughtError,
138 root,
139 fiber,
140 errorInfo,
141 );
142 } else {
143 logCaughtError(root, fiber, errorInfo);
144 }
145 };
146 }
147
148 const inst = fiber.stateNode;
149 if (inst !== null && typeof inst.componentDidCatch === 'function') {
150 // $FlowFixMe[missing-this-annot]
151 update.callback = function callback() {
152 if (__DEV__) {
153 markFailedErrorBoundaryForHotReloading(fiber);
154 }
155 if (__DEV__) {
156 runWithFiberInDEV(
157 errorInfo.source,
158 logCaughtError,
159 root,
160 fiber,
161 errorInfo,
162 );
163 } else {
164 logCaughtError(root, fiber, errorInfo);
165 }
166 if (typeof getDerivedStateFromError !== 'function') {
167 // To preserve the preexisting retry behavior of error boundaries,
168 // we keep track of which ones already failed during this batch.
169 // This gets reset before we yield back to the browser.
170 // TODO: Warn in strict mode if getDerivedStateFromError is
171 // not defined.
172 markLegacyErrorBoundaryAsFailed(this);
173 }
174 if (__DEV__) {
175 callComponentDidCatchInDEV(this, errorInfo);

Callers 3

updateClassComponentFunction · 0.90
captureCommitPhaseErrorFunction · 0.90
throwExceptionFunction · 0.85

Calls 9

runWithFiberInDEVFunction · 0.90
logCaughtErrorFunction · 0.90
includesSomeLaneFunction · 0.90
componentDidCatchMethod · 0.65
errorMethod · 0.65
getDerivedStateFromErrorFunction · 0.50

Tested by

no test coverage detected