Skip to content

feat: add ErrorBoundary to prevent full-page crashes#3350

Merged
seefs001 merged 2 commits intoQuantumNous:mainfrom
goodmorning10:feat/error-boundary
Apr 8, 2026
Merged

feat: add ErrorBoundary to prevent full-page crashes#3350
seefs001 merged 2 commits intoQuantumNous:mainfrom
goodmorning10:feat/error-boundary

Conversation

@goodmorning10
Copy link
Copy Markdown
Contributor

@goodmorning10 goodmorning10 commented Mar 20, 2026

📝 Description

Currently the project has no React Error Boundary. Any JS error thrown during component rendering (e.g. unexpected data from the backend)
causes a full white screen crash with no recovery option.

This PR adds an ErrorBoundary component wrapping the content area in PageLayout. On error, it displays a Semi UI styled error page with a
reload button. Header, sidebar, and footer remain functional.

🚀 Type of change

  • ✨ New feature

🔗 Related Issue

  • None

✅ Checklist

  • Human-written: I wrote this description myself without AI filler.
  • Deep understanding: I fully understand how these changes work and their potential impact.
  • Focused scope: This PR contains no unrelated changes.
  • Locally verified: Tested locally and verified working.
  • Security compliant: No credentials exposed, follows project conventions.

📸 Proof of Work

This PR updates 9 files in total.

Added web/src/components/common/ErrorBoundary.jsx as a class-based React ErrorBoundary using
getDerivedStateFromError and componentDidCatch.

Updated web/src/components/layout/PageLayout.jsx to wrap <App /> with <ErrorBoundary>.

Added the related ErrorBoundary i18n texts to:
web/src/i18n/locales/en.json
web/src/i18n/locales/fr.json
web/src/i18n/locales/ja.json
web/src/i18n/locales/ru.json
web/src/i18n/locales/vi.json
web/src/i18n/locales/zh-CN.json
web/src/i18n/locales/zh-TW.json

No new dependencies were added, supports dark mode.

The implementation uses the existing @douyinfe/semi-ui and @douyinfe/semi-illustrations components.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 20, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Added a React ErrorBoundary component, wrapped the app with it in PageLayout, and added two i18n keys (page-render error message and reload label) across multiple locale JSON files.

Changes

Cohort / File(s) Summary
Error Boundary
web/src/components/common/ErrorBoundary.jsx
New React class component ErrorBoundary using getDerivedStateFromError + componentDidCatch; logs errors and renders a centered fallback UI with localized description and a primary "Reload" button that calls window.location.reload(). Exported as withTranslation()(ErrorBoundary).
Layout Integration
web/src/components/layout/PageLayout.jsx
Wraps <App /> with <ErrorBoundary> inside the layout Content area.
i18n Locales
web/src/i18n/locales/en.json, web/src/i18n/locales/fr.json, web/src/i18n/locales/ja.json, web/src/i18n/locales/ru.json, web/src/i18n/locales/vi.json, web/src/i18n/locales/zh-CN.json, web/src/i18n/locales/zh-TW.json
Added two translation keys to each locale: "页面渲染出错,请刷新页面重试" (page render error message) and "刷新页面" (reload button label). Adjusted trailing punctuation where needed to append keys.

Sequence Diagram(s)

sequenceDiagram
    participant App as App (child)
    participant EB as ErrorBoundary
    participant Console as Console
    participant User as User
    participant Browser as Browser

    App->>EB: render / lifecycle (throws error)
    EB->>EB: getDerivedStateFromError() sets hasError=true
    EB->>Console: componentDidCatch(error, errorInfo) -> console.error(...)
    EB-->>User: render fallback UI (message + "Reload" button)
    User->>EB: clicks "Reload" button
    EB->>Browser: window.location.reload()
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • seefs001
  • Calcium-Ion

Poem

🐰
I hopped where render shadows lay,
I stitched a net to catch the fray,
A gentle note and button bright,
Tap to refresh — the world turns right.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add ErrorBoundary to prevent full-page crashes' clearly and specifically summarizes the main change—adding an ErrorBoundary component to handle rendering errors and prevent full-page crashes, which is exactly what the changeset implements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web/src/components/common/ErrorBoundary.jsx`:
- Around line 37-46: ErrorBoundary currently uses hardcoded Chinese strings for
the fallback description and Button label; wrap the ErrorBoundary class
component with the withTranslation() HOC and replace the hardcoded literals with
translated keys via this.props.t(...) (e.g., replace
description={this.props.description || '页面渲染出错,请刷新页面重试'} and the Button children
'刷新页面' with this.props.t('error.renderFailed') and
this.props.t('action.refresh') or your chosen keys), ensuring you import
withTranslation and export the component as withTranslation()(ErrorBoundary).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3fa33442-9d44-4467-9976-6e3d9c732257

📥 Commits

Reviewing files that changed from the base of the PR and between ed6ff0f and 36dc690.

📒 Files selected for processing (2)
  • web/src/components/common/ErrorBoundary.jsx
  • web/src/components/layout/PageLayout.jsx

Comment thread web/src/components/common/ErrorBoundary.jsx Outdated
@ghost

This comment was marked as spam.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web/src/i18n/locales/ru.json`:
- Around line 3326-3328: The two new Russian translations were added at the JSON
root instead of under the "translation" namespace, so i18next won't find them;
move the entries with keys "页面渲染出错,请刷新页面重试" and "刷新页面" into the existing
"translation" object alongside the other keys (same structure used for lines
3-3325) so the lookup for those Chinese source strings resolves correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cc5881e0-0c14-41f9-a904-fbaaceae98b2

📥 Commits

Reviewing files that changed from the base of the PR and between 3060f9c and fc35b36.

📒 Files selected for processing (7)
  • web/src/i18n/locales/en.json
  • web/src/i18n/locales/fr.json
  • web/src/i18n/locales/ja.json
  • web/src/i18n/locales/ru.json
  • web/src/i18n/locales/vi.json
  • web/src/i18n/locales/zh-CN.json
  • web/src/i18n/locales/zh-TW.json
✅ Files skipped from review due to trivial changes (4)
  • web/src/i18n/locales/zh-TW.json
  • web/src/i18n/locales/zh-CN.json
  • web/src/i18n/locales/fr.json
  • web/src/i18n/locales/en.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/src/i18n/locales/ja.json
  • web/src/i18n/locales/vi.json

Comment thread web/src/i18n/locales/ru.json Outdated
@seefs001
Copy link
Copy Markdown
Collaborator

seefs001 commented Apr 6, 2026

改一下上面的内容就可以合并了

seefs001
seefs001 previously approved these changes Apr 8, 2026
Comment thread web/src/i18n/locales/en.json Outdated
"例如:gpt-4.1-nano,regex:^claude-.*$,regex:^sora-.*$": "Example: gpt-4.1-nano,regex:^claude-.*$,regex:^sora-.*$",
"支持精确匹配;使用 regex: 开头可按正则匹配。": "Supports exact matching. Use a regex: prefix for regex matching."
}
},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看起来翻译资源的层级不对呢

@seefs001 seefs001 merged commit 48695e0 into QuantumNous:main Apr 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants