Course outline

React / Coordinated application behavior / Lesson 14

Error boundaries and bounded recovery

Contain descendant render failures with meaningful fallbacks, explicit reset behavior, and separate event and async error handling.

About 24 min read20 worked examples20 practice exercisesContent reviewed
On this page

Lesson goals

  • Place boundaries around independently recoverable regions.
  • Explain reset, reporting, and uncovered error paths.
  • Verify fallback and recovery without concealing the cause.
  • Choose an error-boundary scope and distinguish descendant render failures from event and async failures.
  • Design and verify a bounded reset, safe reporting, and a meaningful recovery path.

Choose a useful boundary

A rendering failure in one panel should not necessarily remove the entire application. An error boundary catches errors in its descendant tree and can display a fallback. Place it around a region whose failure can be explained and recovered independently, such as a dashboard panel. A boundary does not catch its own errors, and it is not a general replacement for handling errors in event callbacks or asynchronous operations.

Display a fallback

The class below uses getDerivedStateFromError to switch to a plain fallback when a descendant fails during rendering. Keep the fallback independent of the failing data and components. Real applications may also implement componentDidCatch for reporting, taking care to avoid sending sensitive data and to account for development and production differences. The pure state derivation itself must not perform network reporting.

jsx Component module for a React host
import { Component } from "react";
export class ErrorBoundary extends Component {
  state = { failed: false };
  static getDerivedStateFromError() { return { failed: true }; }
  render() {
    return this.state.failed ? <p role="alert">This panel could not be displayed.</p> : this.props.children;
  }
}
Expected output
A descendant render failure displays This panel could not be displayed.

A descendant failure sets boundary state, replacing that subtree with a simple alert.

Reset deliberately

Changing a boundary key remounts it with fresh state. This example gives the user a retry control outside the boundary so it remains available while the fallback is shown. A reset only tries rendering again; if the input or underlying defect remains, the same error can recur. Restore or refresh the real dependency before retrying when appropriate, and avoid silently repeating a failing operation forever.

jsx Component module for a React host
import { useState } from "react";
import { ErrorBoundary } from "./ErrorBoundary";
export default function Panel({ children }) {
  const [attempt, setAttempt] = useState(0);
  return <section><button onClick={() => setAttempt(n => n + 1)}>Retry panel</button><ErrorBoundary key={attempt}>{children}</ErrorBoundary></section>;
}
Expected output
Retry panel remains available while the fallback is displayed.

The retry increments a key and remounts the boundary and its children; it does not repair their inputs.

Handle other failure paths

A rejected fetch or failed save needs an explicit result or error state owned by that operation. Catch the failure where its promise or event is handled, present an actionable message, and preserve a draft where safe. Server rendering and failures inside the boundary itself have separate handling requirements. Do not rely on a render boundary as a security control or as proof that an external mutation did not happen.

Test containment and recovery

In a controlled test, make a child throw during render and verify that the fallback appears while a neighboring panel remains usable. Remove the simulated fault, activate retry and confirm the child returns. Test an event rejection separately and verify the operation-specific message. Check keyboard access to retry and avoid recording actual private input in diagnostic reports. Capture enough context to identify the failing component without treating a fallback as a successful repair.

Place a boundary around a recoverable region

An error boundary is a React component that can replace a failing descendant tree with a fallback. The useful placement follows a product boundary: a chart can fail while an independent table and page navigation remain available. Wrapping every tiny element can make recovery confusing, while one boundary around an entire application may discard more useful interface than necessary. Decide what the user can still do and what data the fallback can safely depend on. A boundary is a containment mechanism, not a fix for the defect that caused the error.

In the React 18.3.1 baseline a class component can implement static getDerivedStateFromError to derive fallback state and componentDidCatch for reporting. Keep the state derivation pure and render a simple fallback independent of the component or data that failed. If the fallback itself throws, that boundary cannot catch its own error; an outer boundary or host-level handling must own it. A boundary around a subtree catches relevant descendant rendering and lifecycle failures, but it does not turn every failure in an application into a recoverable render error.

Distinguish render errors from operation failures

A save invoked by a click and a rejected asynchronous request belong to the operation that starts them. Catch or represent their failures in that event or async flow, show a truthful message, and retain a safe draft when the contract allows retry. Do not assume that an error boundary catches an ordinary event-handler exception, a timer callback, a rejected promise, or a server-rendering failure. Those paths need their own handling under the selected runtime and framework. A fallback is also not authorization and does not prove that a remote write was rolled back.

If a save times out, the server may have processed it even though the browser lacks confirmation. Show an uncertain outcome when appropriate and use an operation identifier and server-enforced idempotency or reconciliation policy before retrying. For an error in the boundary’s own fallback, an outer boundary can contain the failure if the tree is designed for it. Separate a missing record, denied access, invalid data, and a failed render according to the application’s disclosure policy; avoid converting them all into a generic success or empty result.

Reset only with a recovery strategy

A reset clears the boundary’s failed state or remounts it with a new key and tries to render the child again. It does not correct corrupt input, fix code, restore a service, or undo a remote action. If the same child and defective input remain, the fallback can appear again immediately. A retry button should identify the operation and be available outside the failing subtree or within a reliable fallback. When appropriate refresh or replace the failed data before retrying, and prevent an uncontrolled loop of automatic retries.

Changing a key replaces the boundary and its descendants, so local drafts and focus inside the old subtree may be lost. Keep a draft in a longer-lived owner if it must survive, and communicate consequences before destructive reset where the product requires it. A reset can be meaningful for an isolated panel with newly validated input; for a persistent programming defect the useful action may instead be to preserve the rest of the page and report the issue. Test both a retry after removing the synthetic fault and a retry while the fault remains.

Report safely without hiding the cause

componentDidCatch receives an error and component information for a caught descendant failure. A production reporting integration can record a safe error category, component context, and an operation or release identifier under its privacy policy. Do not send passwords, access tokens, entire form drafts, or raw private responses simply because an error occurred. A fallback should give the user an understandable status and any supported recovery action; it should not claim success. Reporting itself can fail, so isolate and handle the reporting transport rather than letting it obscure the original failure.

Development and production error propagation or logging can differ. Do not suppress every console message merely to make a test quiet, and do not count fallback displays as repaired incidents. Keep getDerivedStateFromError free of network calls and other side effects; use the appropriate reporting boundary for diagnostics. Error boundaries also do not replace monitoring at server and service boundaries. Record enough synthetic context in tests to confirm reporting is invoked without using real user data or contacting a production telemetry endpoint.

Verify containment, reset, and uncovered paths

Construct a controlled child that throws during render only when a supplied fault flag is true. Wrap the chart region and leave a sibling table outside it. Assert the fallback is visible and the table remains usable. Turn off the synthetic fault, invoke the documented retry, and verify the chart returns; leave the fault on in another test and verify the fallback recurs without an infinite retry loop. Confirm keyboard access to the retry button and the intended focus behavior after recovery.

Test an event-handler failure and a rejected save separately, because a passing render-boundary test does not establish those paths. Exercise an outer boundary if the inner fallback fails, and test unmounting or changing keys where draft lifetime matters. Use renderer-aware test coordination and isolate the test root and fake reporting service. The fragments below target React 18.3.1 or explicit synthetic state fixtures; they are non-runnable here and results are reasoned predictions, not claims of an executed browser or remote operation.

20 worked examples

1. Contain a chart failure

Problem: Keep a sibling table available when a chart throws during rendering.

  1. The throwing chart is a descendant of the boundary.
  2. The table is outside that failing subtree and is not replaced by its fallback.
jsx Synthetic React 18.3.1 boundary or recovery fixture.
class Boundary extends React.Component {
  state = { failed: false };
  static getDerivedStateFromError() { return { failed: true }; }
  render() { return this.state.failed ? <p role="alert">Chart unavailable</p> : this.props.children; }
}
function Chart() { throw new Error("Synthetic chart fault"); }
const view = <><Boundary><Chart /></Boundary><table><tbody><tr><td>Table works</td></tr></tbody></table></>;

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: The chart boundary displays Chart unavailable while the sibling table remains in the tree.

Why this result follows: The throwing chart is a descendant of the boundary. The table is outside that failing subtree and is not replaced by its fallback.

2. Independent panels

Problem: Contain one synthetic panel failure without replacing another panel boundary.

  1. Each boundary owns its own descendant region.
  2. The second panel does not depend on the first boundary’s failed state.
jsx Synthetic React 18.3.1 boundary or recovery fixture.
class Boundary extends React.Component { state = { failed: false }; static getDerivedStateFromError() { return { failed: true }; } render() { return this.state.failed ? <p>Panel failed</p> : this.props.children; } }
function Broken() { throw new Error("Synthetic"); }
const view = <><Boundary><Broken /></Boundary><Boundary><p>Second panel</p></Boundary></>;

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: The first boundary displays Panel failed and the second displays Second panel.

Why this result follows: Each boundary owns its own descendant region. The second panel does not depend on the first boundary’s failed state.

3. Fallback must be independent

Problem: Use plain fallback text rather than rerendering the failing child.

  1. getDerivedStateFromError changes the boundary state.
  2. The simple fallback does not call the failing Fault component again during its render.
jsx Synthetic React 18.3.1 boundary or recovery fixture.
class Boundary extends React.Component {
  state = { failed: false };
  static getDerivedStateFromError() { return { failed: true }; }
  render() { return this.state.failed ? <p role="alert">Panel unavailable</p> : this.props.children; }
}
function Fault() { throw new Error("Synthetic"); }
const view = <Boundary><Fault /></Boundary>;

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: A descendant render failure selects the plain Panel unavailable alert.

Why this result follows: getDerivedStateFromError changes the boundary state. The simple fallback does not call the failing Fault component again during its render.

4. Retry after repair

Problem: Remount a failed subtree after replacing the synthetic faulty input.

  1. The changed key creates a fresh boundary state.
  2. The replacement child no longer throws for the repaired input.
jsx Synthetic React 18.3.1 boundary or recovery fixture.
class Boundary extends React.Component { state = { failed: false }; static getDerivedStateFromError() { return { failed: true }; } render() { return this.state.failed ? <p>Failed</p> : this.props.children; } }
function Panel({ broken }) { if (broken) throw new Error("Synthetic"); return <p>Panel ready</p>; }
// First render <Boundary key={0}><Panel broken /></Boundary>; then render key 1 with broken={false}.

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: The first render shows Failed; after the changed key and repaired input, Panel ready appears.

Why this result follows: The changed key creates a fresh boundary state. The replacement child no longer throws for the repaired input.

5. Retry without repair

Problem: Show why a changed boundary key does not fix unchanged faulty input.

  1. The new key clears the previous boundary state by remounting.
  2. The child still throws, so the replacement boundary enters its fallback too.
jsx Synthetic React 18.3.1 boundary or recovery fixture.
class Boundary extends React.Component { state = { failed: false }; static getDerivedStateFromError() { return { failed: true }; } render() { return this.state.failed ? <p>Failed</p> : this.props.children; } }
function Panel() { throw new Error("Still broken"); }
// Render <Boundary key={0}><Panel /></Boundary>, then repeat with key 1.

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: The fallback appears again after the new boundary retries the same throwing child.

Why this result follows: The new key clears the previous boundary state by remounting. The child still throws, so the replacement boundary enters its fallback too.

6. Event error is separate

Problem: Handle a synthetic click failure inside its owning event handler.

  1. The exception occurs inside the event callback, not descendant rendering.
  2. The local try/catch converts it into a visible operation result.
jsx Synthetic React 18.3.1 boundary or recovery fixture.
function Save() {
  const [message, setMessage] = React.useState("");
  function save() { try { throw new Error("Synthetic save fault"); } catch { setMessage("Save failed"); } }
  return <><button type="button" onClick={save}>Save</button><p role="status">{message}</p></>;
}

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: Activating Save displays Save failed through the operation’s own state.

Why this result follows: The exception occurs inside the event callback, not descendant rendering. The local try/catch converts it into a visible operation result.

7. Rejected save

Problem: Observe and report an asynchronous save rejection at its owner.

  1. The event handler awaits the promise it starts.
  2. Its catch branch owns the rejection rather than relying on a render boundary.
jsx Synthetic React 18.3.1 boundary or recovery fixture.
function Save({ save }) {
  const [message, setMessage] = React.useState("");
  async function submit() { try { await save(); setMessage("Saved"); } catch { setMessage("Save failed; retry"); } }
  return <><button type="button" onClick={submit}>Save</button><p role="status">{message}</p></>;
}
// Supply a fake save that rejects.

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: The status becomes Save failed; retry after the fake rejection.

Why this result follows: The event handler awaits the promise it starts. Its catch branch owns the rejection rather than relying on a render boundary.

8. Preserve a draft on failure

Problem: Retain the submitted synthetic text when a save does not succeed.

  1. The failure transition carries the original draft into the result.
  2. It does not clear the user’s safe input or claim persistence.
javascript Synthetic React 18.3.1 boundary or recovery fixture.
function failedSave(draft) { return { draft, status: "error", message: "Save failed; retry" }; }
const next = failedSave("Report");

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: next retains draft Report and reports a retryable error.

Why this result follows: The failure transition carries the original draft into the result. It does not clear the user’s safe input or claim persistence.

9. Outer fallback

Problem: Contain a failure thrown by an inner boundary’s own fallback.

  1. The inner boundary cannot catch an error thrown by its own render.
  2. The outer boundary is an ancestor of the failing inner subtree.
jsx Synthetic React 18.3.1 boundary or recovery fixture.
class Outer extends React.Component { state = { failed: false }; static getDerivedStateFromError() { return { failed: true }; } render() { return this.state.failed ? <p>Outer fallback</p> : this.props.children; } }
class Inner extends React.Component { state = { failed: false }; static getDerivedStateFromError() { return { failed: true }; } render() { if (this.state.failed) throw new Error("Fallback fault"); return this.props.children; } }
function Broken() { throw new Error("Child fault"); }
const view = <Outer><Inner><Broken /></Inner></Outer>;

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: The outer boundary can display Outer fallback when the inner fallback throws.

Why this result follows: The inner boundary cannot catch an error thrown by its own render. The outer boundary is an ancestor of the failing inner subtree.

10. Unknown remote outcome

Problem: Avoid claiming rollback when a synthetic save times out.

  1. A client timeout does not establish whether the server applied the write.
  2. The operation id can support a separately defined reconciliation policy.
javascript Synthetic React 18.3.1 boundary or recovery fixture.
const outcome = { operationId: "save-7", transport: "timeout", serverResult: "unknown" };
const message = outcome.serverResult === "unknown" ? "Check save status" : "Resolved";

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: message is Check save status.

Why this result follows: A client timeout does not establish whether the server applied the write. The operation id can support a separately defined reconciliation policy.

11. Safe reporting payload

Problem: Limit a synthetic error report to non-sensitive diagnostic fields.

  1. The fixture selects only the diagnostic fields needed for this example.
  2. It does not copy form contents or credentials into the report.
javascript Synthetic React 18.3.1 boundary or recovery fixture.
const report = { category: "chart-render", release: "demo-1", component: "ChartPanel" };
const allowed = Object.keys(report);

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: allowed contains category, release, and component; no draft or token is included.

Why this result follows: The fixture selects only the diagnostic fields needed for this example. It does not copy form contents or credentials into the report.

12. Separate report from derivation

Problem: Keep a boundary’s state derivation pure while reporting in its lifecycle method.

  1. The static derivation only returns the next fallback state.
  2. componentDidCatch owns the separate reporting call under the host’s policy.
jsx Synthetic React 18.3.1 boundary or recovery fixture.
class Boundary extends React.Component {
  state = { failed: false };
  static getDerivedStateFromError() { return { failed: true }; }
  componentDidCatch(error, info) { this.props.report({ category: "render", componentStack: info.componentStack }); }
  render() { return this.state.failed ? <p>Unavailable</p> : this.props.children; }
}

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: A caught descendant error selects Unavailable and passes diagnostic context to the supplied fake reporter.

Why this result follows: The static derivation only returns the next fallback state. componentDidCatch owns the separate reporting call under the host’s policy.

13. Retry control remains available

Problem: Place the retry control outside a boundary’s failed descendant subtree.

  1. The button is a sibling of the boundary rather than its failing child.
  2. Changing attempt can remount the boundary after the owner repairs the input.
jsx Synthetic React 18.3.1 boundary or recovery fixture.
function Panel({ attempt, retry, children }) {
  return <section><button type="button" onClick={retry}>Retry panel</button><Boundary key={attempt}>{children}</Boundary></section>;
}
// Boundary is an error-boundary class and its child throws.

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: Retry panel remains outside the fallback subtree and can be activated.

Why this result follows: The button is a sibling of the boundary rather than its failing child. Changing attempt can remount the boundary after the owner repairs the input.

14. Preserve draft outside reset

Problem: Keep an unsaved draft in an owner that outlives a keyed panel reset.

  1. The draft state belongs to Page outside the boundary.
  2. Changing the boundary key replaces that subtree, not the retained Page owner.
jsx Synthetic React 18.3.1 boundary or recovery fixture.
function Page({ attempt }) {
  const [draft, setDraft] = React.useState("Report");
  return <><label>Draft<input value={draft} onChange={e => setDraft(e.target.value)} /></label><Boundary key={attempt}><p>Panel</p></Boundary></>;
}
// Change attempt while Page remains mounted.

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: The Page draft remains while the keyed boundary subtree is remounted.

Why this result follows: The draft state belongs to Page outside the boundary. Changing the boundary key replaces that subtree, not the retained Page owner.

15. Missing is not a render crash

Problem: Represent a known absent record as an explicit normal branch.

  1. The null input is a documented outcome in this contract.
  2. The component selects a normal missing branch rather than using an error boundary.
jsx Synthetic React 18.3.1 boundary or recovery fixture.
function Record({ record }) {
  if (record === null) return <p>Record not found</p>;
  return <h1>{record.title}</h1>;
}
const view = <Record record={null} />;

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: The view displays Record not found without throwing.

Why this result follows: The null input is a documented outcome in this contract. The component selects a normal missing branch rather than using an error boundary.

16. Pending operation failure

Problem: Keep a failed local check distinct from a successful completion.

  1. The supplied false outcome selects the failure branch.
  2. The state does not label a failed check as successful.
javascript Synthetic React 18.3.1 boundary or recovery fixture.
function finishCheck(ok) { return ok ? { status: "success", message: "Ready" } : { status: "error", message: "Check unavailable" }; }
const result = finishCheck(false);

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: result has status error and message Check unavailable.

Why this result follows: The supplied false outcome selects the failure branch. The state does not label a failed check as successful.

17. Server rendering boundary

Problem: Recognize that a client render boundary is not a complete server error policy.

  1. A client boundary is not a general handler for every server-rendering failure.
  2. The deployment integration must define its own response and reporting behavior.
javascript Synthetic React 18.3.1 boundary or recovery fixture.
const fixture = { phase: "server-render", boundary: "client panel boundary", expectedOwner: "framework or server error handling" };

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: The fixture assigns server-render failure handling to the framework or server policy.

Why this result follows: A client boundary is not a general handler for every server-rendering failure. The deployment integration must define its own response and reporting behavior.

18. Controlled recovery test

Problem: Describe a deterministic containment, repair, and retry sequence for an isolated chart.

  1. The initial fault is confined to the chart region.
  2. The fault is removed before the retry attempts rendering again.
javascript Synthetic React 18.3.1 boundary or recovery fixture.
const test = { initialFault: true, expect: "Chart unavailable", sibling: "Table works", repair: "set fault false", retry: "activate Retry panel", final: "Chart ready" };

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: The fixture expects a fallback, usable sibling, and successful retry after repair; it does not claim execution.

Why this result follows: The initial fault is confined to the chart region. The fault is removed before the retry attempts rendering again.

19. Repeat fault without loop

Problem: Keep a persistent synthetic fault visible without automatic retrying forever.

  1. No user request selects the waiting branch.
  2. A deliberate request permits one retry under this bounded fixture policy.
javascript Synthetic React 18.3.1 boundary or recovery fixture.
function retryDecision({ failed, userRequested }) { return failed && userRequested ? "retry once" : "wait"; }
const decisions = [retryDecision({ failed: true, userRequested: false }), retryDecision({ failed: true, userRequested: true })];

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: decisions is ["wait", "retry once"].

Why this result follows: No user request selects the waiting branch. A deliberate request permits one retry under this bounded fixture policy.

20. Accessible fallback action

Problem: Expose a named retry control alongside a meaningful failure message.

  1. The failure is communicated in text rather than color alone.
  2. The native button gives the user a named action to request recovery.
jsx Synthetic React 18.3.1 boundary or recovery fixture.
function Fallback({ retry }) { return <div role="alert"><p>Panel unavailable</p><button type="button" onClick={retry}>Retry panel</button></div>; }
const view = <Fallback retry={() => console.log("retry")} />;

Trace the stated failure and recovery; no execution or remote operation is claimed.

Expected result: The alert contains Panel unavailable and a button named Retry panel.

Why this result follows: The failure is communicated in text rather than color alone. The native button gives the user a named action to request recovery.

Common errors and fixes

The entire page disappears when a panel fails.

Why it happens
The failing subtree has no suitable local boundary.
How to fix it
Wrap an independently recoverable region in a boundary.
Prevent it next time
Test a controlled descendant render failure.

Retry immediately shows the same fallback.

Why it happens
Reset remounts the subtree but the broken input remains.
How to fix it
Repair or refresh the underlying input before retrying.
Prevent it next time
Document what must change for recovery.

A failed save is not caught by the boundary.

Why it happens
The failure occurs in an event or asynchronous operation.
How to fix it
Handle the rejection in its owning operation.
Prevent it next time
Test render and operation failure paths separately.

20 practice exercises

1. A chart throws while its sibling table works. Where can a boundary help?

Show hint

Keep the independently useful sibling outside the chart boundary.

Show worked solution

Wrap the chart region so the table can remain usable. Supply a fallback independent of the chart data and a retry only when a meaningful recovery path exists. Verify that the sibling remains interactive.

Wrap the chart region so its render failure displays a simple chart-specific fallback while the table remains usable. Keep the fallback independent of the broken data and offer retry only when the owner can attempt a meaningful recovery. Test the table interaction during the failure.

Check your solution

  • The chart failure is contained locally.
  • The sibling table remains interactive.

2. Why does changing a boundary key not guarantee recovery?

Show hint

A new identity resets boundary state but does not repair its input.

Show worked solution

A new key remounts the subtree and clears boundary state, but does not change a defective child or its inputs. Correct or refresh the underlying cause and then test the retry.

Changing the key remounts the boundary and its descendants, clearing the failed state. The same defect or malformed input will make the replacement fail again. Repair or refresh the cause first, then test a user-directed retry and its effect on local drafts.

Check your solution

  • The key change is identified as a remount.
  • The underlying defect must be addressed separately.

3. A chart throws during render while a neighboring table is independent. Choose a useful boundary.

Show hint

Contain the independently recoverable chart region.

Show worked solution

Wrap the chart in an error boundary and keep the table outside that boundary. Show a simple chart-unavailable fallback that does not depend on the failing chart data. In a controlled test, verify the table remains usable while the chart fallback is visible.

Check your solution

  • The chart failure selects its fallback.
  • The sibling table remains available.

4. A boundary fallback tries to render the same broken chart again. Explain the risk and repair.

Show hint

The fallback should not depend on the failed subtree.

Show worked solution

Replace the fallback with simple independent text and a supported recovery action. Rendering the broken chart again from the fallback can throw again, and a boundary cannot catch its own render failure. An outer boundary may contain that separate failure when deliberately provided.

Check your solution

  • The fallback does not render the broken chart.
  • An outer boundary owns any fallback failure if needed.

5. A panel fails because its input is malformed. Describe a meaningful retry sequence.

Show hint

Repair or replace the cause before resetting the boundary.

Show worked solution

Validate or refresh the panel input, then let the user activate a retry that clears or remounts the boundary. Confirm the repaired child renders and that a still-malformed input produces the fallback again. Reset alone does not change the defective data.

Check your solution

  • The input is repaired before the successful retry.
  • Persistent faulty input is tested separately.

6. A retry changes the boundary key while the child still throws. Predict the visible result.

Show hint

A new key remounts; it does not repair the child.

Show worked solution

The new boundary starts with fresh state and attempts to render the same child. Because the child still throws, the new boundary displays its fallback again. Avoid an automatic unbounded retry loop and present a useful recovery or reporting path.

Check your solution

  • The boundary is remounted with fresh state.
  • The unchanged fault causes the fallback to recur.

7. A Save click throws synchronously inside its handler. Explain where to handle the failure.

Show hint

An ordinary event callback is a separate failure boundary.

Show worked solution

Catch the error in the save handler or the owning operation and set an explicit failure state. Show a useful message and preserve a safe draft if retry is supported. A render error boundary should not be assumed to catch this ordinary event-handler exception.

Check your solution

  • The event owner handles the exception.
  • The user receives truthful failure feedback.

8. A fake save promise rejects after a click. Design the observable failure path.

Show hint

Await the owned promise and handle rejection.

Show worked solution

Use try/catch around await save() inside the event handler and set an error message such as Save failed; retry. Keep the draft when safe and do not display Saved for the rejection. Test the rejection with a controlled promise separately from a render failure.

Check your solution

  • The rejection is observed by the handler.
  • The interface shows failure and retains the safe draft.

9. A save request times out but the server may have processed it. Choose a truthful status.

Show hint

A client timeout leaves the remote outcome uncertain.

Show worked solution

Show an unknown or checking status and reconcile using an operation identifier and the server’s actual idempotency policy. Do not state that the write was rolled back merely because the browser stopped waiting. Offer retry only under a policy that addresses potential duplicate effects.

Check your solution

  • The interface does not claim confirmed rollback.
  • Recovery follows a defined server operation policy.

10. An inner boundary fallback throws. Explain which boundary can handle that new render failure.

Show hint

A boundary cannot catch an error in its own render.

Show worked solution

Place an independent outer boundary above the inner boundary if that broader region can recover. The outer boundary can display its own simple fallback when the inner fallback throws. Also fix the inner fallback; nesting does not make a broken fallback harmless.

Check your solution

  • The inner boundary does not catch its own failure.
  • A suitable outer boundary can contain the new error.

11. A boundary reports a chart error. Select useful diagnostic fields without exposing private input.

Show hint

Minimize the report to the information needed for diagnosis.

Show worked solution

Send a safe category such as chart-render, a release identifier, and appropriate component context through the approved reporting integration. Exclude passwords, tokens, and full user drafts. Handle reporting failures independently and verify the payload with a fake reporter in tests.

Check your solution

  • The report includes a useful non-sensitive category.
  • Private drafts and credentials are excluded.

12. Where should an error boundary place diagnostic reporting relative to its getDerivedStateFromError method?

Show hint

Keep state derivation pure and reporting at its lifecycle boundary.

Show worked solution

Use static getDerivedStateFromError to return fallback state without a network call, and use componentDidCatch or the application’s documented reporting integration to record safe diagnostics. Test the fallback and fake reporting behavior separately; development logging can differ from production.

Check your solution

  • The state derivation has no reporting side effect.
  • Reporting follows the approved safe integration.

13. A retry button is inside the descendant that throws. Redesign its placement.

Show hint

The recovery control must survive the failed subtree.

Show worked solution

Put Retry panel in a reliable fallback or outside the boundary that wraps the faulty child. The control can then ask the owner to repair input and reset the boundary. Verify that it remains keyboard accessible while the fallback is displayed.

Check your solution

  • Retry remains available during fallback.
  • Activation follows a documented repair and reset path.

14. A keyed reset discards a panel’s unsaved draft. Choose a longer-lived owner if the draft must survive.

Show hint

Place the draft outside the subtree whose key changes.

Show worked solution

Lift the draft to a parent that remains mounted across the boundary reset and pass its value and update callback into the panel. Changing the boundary key then resets the panel subtree while the owner retains the draft. Define cleanup or persistence separately when the parent itself leaves.

Check your solution

  • The draft owner survives the keyed reset.
  • The reset does not silently discard the retained draft.

15. A record is known to be absent. Decide whether a normal missing branch or a thrown render error is appropriate.

Show hint

Expected domain outcomes can be modeled explicitly.

Show worked solution

Render a Record not found state for a documented null or missing response rather than throwing solely to invoke a boundary. Keep denial and network failure distinct under the product’s disclosure policy. Reserve the boundary for unexpected descendant failures that the region cannot render normally.

Check your solution

  • The expected missing case has a normal branch.
  • The result is not falsely presented as successful data.

16. A fallback says "Saved" after a panel render failure. Explain the misleading claim and replace it.

Show hint

The fallback should describe the actual failure.

Show worked solution

Show a message such as Panel unavailable and offer Retry panel only when a supported recovery exists. Rendering failure does not establish that a save succeeded or failed. Keep operation status and render containment as separate pieces of information.

Check your solution

  • The fallback does not claim a successful save.
  • Any retry corresponds to a real supported action.

17. A boundary wraps the whole page, but a chart alone can recover. Compare a narrower placement.

Show hint

Match the boundary to an independently useful region.

Show worked solution

Place a local boundary around the chart so navigation and an independent table can remain usable when the chart throws. Keep a broader application-level policy for failures outside that panel if appropriate. Test both containment and the sibling’s continued interaction.

Check your solution

  • The chart failure does not remove the table.
  • The local fallback explains the failed region.

18. Design a controlled test for a successful retry after a render fault.

Show hint

Make the fault and its repair explicit in the fixture.

Show worked solution

Render a child with a synthetic fault flag set true and assert the boundary fallback. Set the flag false, activate the retry control, and wait for the child’s ready content. Assert a sibling remains usable and verify cleanup of the isolated test root.

Check your solution

  • The initial fault shows the fallback.
  • The repaired retry shows the child again.

19. Test a persistent fault without creating an endless automatic retry cycle in the affected panel.

Show hint

Keep retry an explicit bounded decision.

Show worked solution

Leave the synthetic fault enabled, activate Retry panel once, and assert that the fallback returns while the control remains available. Confirm the component does not repeatedly retry by itself. Record a safe diagnostic and do not treat the recurring fallback as successful recovery.

Check your solution

  • One deliberate retry produces the fallback again.
  • No unbounded automatic retry is started.

20. A server-rendered route fails before client hydration. Identify the appropriate error-handling boundary.

Show hint

Server rendering is owned by the framework or server runtime.

Show worked solution

Use the selected framework or server’s documented error response and reporting mechanism for the server-render failure. A client component error boundary is not a complete server error policy. Test the response in an isolated deployment and avoid exposing private diagnostics to the user.

Check your solution

  • The server or framework owns the server failure path.
  • The client boundary is not presented as complete server protection.

Key takeaways

  • Boundaries contain descendant rendering failures.
  • Reset must accompany a real recovery strategy.
  • Handle event and asynchronous failures at their owner.
  • A boundary contains a descendant failure but does not repair the cause.
  • Resetting a key remounts state and can discard local drafts.
  • Handle event, async, and server failures at their own boundaries.

Official references