Files
2nd/10_Wiki/Topics/Domain_Programming/Frontend/Error Boundaries.md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

6.1 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-error-boundaries Error Boundaries 10_Wiki/Topics verified self
React Error Boundary
ErrorBoundary
getDerivedStateFromError
none A 0.9 applied
react
error-handling
frontend
resilience
2026-05-10 pending
language framework
TypeScript React

Error Boundaries

매 한 줄

"매 React subtree 의 의 render-time error 의 catch 의 의 fallback UI 의 의 swap 의 component". 의 entire app crash 의 의 prevent 의 — 의 try/catch 의 declarative React equivalent. 2026 의 의 매 React 19 의 still 의 class component 의만 의 의 Error Boundary 의 author 의 가능 (의 hook API 의 X).

매 핵심

매 catch 의 X 의 것

  • Event handler error (의 try/catch 의 사용).
  • Async code (setTimeout, promise) — Error Boundary 의 의 reach 의 X.
  • SSR (의 server-side throw 의 의 catch 의 의 X).
  • Boundary itself 의 throw.

매 catch 의 것

  • 의 child render error.
  • 의 lifecycle method error.
  • 의 constructor error.

매 hierarchy strategy

  • Top-level: 의 fallback "Something went wrong" 의 의 entire app crash 의 의 prevent.
  • Route-level: 의 broken page 의만 의 의 fail.
  • Widget-level: 의 chart, embed, third-party 의 의 isolate.

매 응용

  1. Production crash 의 reporting (Sentry, Datadog).
  2. Third-party widget 의 isolation.
  3. Per-route error UI (Next.js error.tsx).
  4. Suspense fallback combo (loading + error).

💻 패턴

기본 class boundary

import { Component, type ReactNode, type ErrorInfo } from "react";

type Props = { fallback: ReactNode; onError?: (e: Error, info: ErrorInfo) => void; children: ReactNode };
type State = { hasError: boolean };

export class ErrorBoundary extends Component<Props, State> {
  state: State = { hasError: false };

  static getDerivedStateFromError(): State {
    return { hasError: true };
  }

  componentDidCatch(error: Error, info: ErrorInfo) {
    this.props.onError?.(error, info);
  }

  render() {
    return this.state.hasError ? this.props.fallback : this.props.children;
  }
}

react-error-boundary 라이브러리

import { ErrorBoundary } from "react-error-boundary";

function Fallback({ error, resetErrorBoundary }: { error: Error; resetErrorBoundary: () => void }) {
  return (
    <div role="alert">
      <p>Something went wrong:</p>
      <pre>{error.message}</pre>
      <button onClick={resetErrorBoundary}>Retry</button>
    </div>
  );
}

<ErrorBoundary
  FallbackComponent={Fallback}
  onError={(error, info) => Sentry.captureException(error, { extra: info })}
  onReset={() => queryClient.resetQueries()}
>
  <Dashboard />
</ErrorBoundary>

Suspense + ErrorBoundary 의 combo

<ErrorBoundary FallbackComponent={Fallback}>
  <Suspense fallback={<Skeleton />}>
    <UserProfile id={userId} />
  </Suspense>
</ErrorBoundary>

의 async event 의 의 manual rethrow

function useAsyncError() {
  const [, setState] = useState();
  return useCallback((e: unknown) => {
    setState(() => { throw e; });
  }, []);
}

function MyComponent() {
  const throwAsync = useAsyncError();
  const onClick = async () => {
    try {
      await fetchData();
    } catch (e) {
      throwAsync(e);  // 매 ErrorBoundary 의 의 reach
    }
  };
  return <button onClick={onClick}>Load</button>;
}

Next.js App Router error.tsx

"use client";

export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) {
  useEffect(() => { console.error(error); }, [error]);
  return (
    <div>
      <h2>Something went wrong</h2>
      <button onClick={reset}>Retry</button>
    </div>
  );
}

Per-route boundary

<Routes>
  <Route path="/" element={<Layout />}>
    <Route index element={
      <ErrorBoundary FallbackComponent={HomeFailed}><Home /></ErrorBoundary>
    } />
    <Route path="dashboard" element={
      <ErrorBoundary FallbackComponent={DashFailed}><Dashboard /></ErrorBoundary>
    } />
  </Route>
</Routes>

의 Sentry 의 integrate

import * as Sentry from "@sentry/react";

const SentryBoundary = Sentry.withErrorBoundary(MyApp, {
  fallback: ({ error, resetError }) => <Fallback error={error} resetErrorBoundary={resetError} />,
  showDialog: true,
});

Reset on prop change

<ErrorBoundary
  FallbackComponent={Fallback}
  resetKeys={[userId]}   // 의 userId 의 의 change 의 시 의 boundary reset
>
  <UserProfile id={userId} />
</ErrorBoundary>

매 결정 기준

상황 Approach
Top-level app crash 의 prevent Single root boundary + telemetry
Route 의 isolation Per-route boundary (Next.js error.tsx)
Third-party widget Tight boundary 의 의 widget 의만
Async data fetch TanStack Query 의 throwOnError + boundary
Form validation Inline error UI — 매 boundary 의 X

기본값: root + per-route + per-widget — 매 layered boundaries.

🔗 Graph

🤖 LLM 활용

언제: production crash protection, third-party widget isolation, Suspense + error 의 combo. 언제 X: form-level validation — 매 inline UI 의 더 적합.

안티패턴

  • No top-level boundary: 의 single child throw 의 의 entire app white-screen.
  • Boundary over async without rethrow: 의 catch 의 의 fail — 의 manual rethrow 의 필요.
  • Eat error silently: 매 telemetry 의 의 X — debug 의 impossible.
  • Reset 의 의 X: user 의 의 retry 의 의 way 의 X — stuck 의 fallback.
  • getDerivedStateFromError 의 의 side effect: pure function 의 의 의 violation.

🧪 검증 / 중복

  • Verified (React 19 docs, react-error-boundary, Next.js App Router error handling, Sentry React SDK).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — async rethrow + Next.js error.tsx + reset key 추가