Skip to content

♻️ refactor: add generic SafeBoundary error boundary with tiered fallback#13321

Merged
Innei merged 1 commit intocanaryfrom
feat/generic-error-boundary
Mar 27, 2026
Merged

♻️ refactor: add generic SafeBoundary error boundary with tiered fallback#13321
Innei merged 1 commit intocanaryfrom
feat/generic-error-boundary

Conversation

@Innei
Copy link
Copy Markdown
Member

@Innei Innei commented Mar 26, 2026

💻 Change Type

  • ♻️ refactor

🔗 Related Issue

N/A

🔀 Description of Change

Introduce a unified SafeBoundary component that replaces scattered custom ErrorBoundary class components (ToolErrorBoundary, EditorErrorBoundary) with a single, generic implementation backed by react-error-boundary (re-exported from @lobehub/ui).

Two-variant fallback strategy:

  • silent (default): minimal dashed-border placeholder with warning icon — for non-critical areas (Inspector, Reasoning, ImageViewer, Tools)
  • alert: full Alert card with error stack + close/retry — for core content (MessageContent, ToolDetail, EditorCanvas)

Injection points (container layer):

  • ContentBlock: wraps Reasoning (silent), MessageContent (alert), ImageFileListViewer (silent), Tools (silent)
  • MessageItem: wraps entire message rendering (alert) as a top-level fallback
  • Inspector: wraps CustomInspector with resetKeys for streaming recovery
  • Tool/Detail: migrated from ToolErrorBoundarySafeBoundary (alert)
  • PluginRender: migrated from ToolErrorBoundarySafeBoundary (alert)
  • EditorCanvas: migrated from EditorErrorBoundarySafeBoundary (alert)

Key features:

  • resetKeys prop for automatic error recovery when props change (e.g., streaming)
  • onError callback for custom error logging
  • withErrorBoundary HOC for wrapping components declaratively
  • Business developers don't need to manually add error boundaries

🧪 How to Test

  • Tested locally
  • Added/updated tests
  • No tests needed
  1. Verify existing EditorCanvas tests pass
  2. Verify no TypeScript errors across changed files
  3. Manually test: tool calls, inspector rendering, markdown messages, editor canvas should all render normally
  4. To test error boundary: temporarily throw in a CustomInspector component — should show silent placeholder instead of crashing the app

📝 Additional Information

  • Old ErrorBoundary.tsx files (ToolErrorBoundary, EditorErrorBoundary) are now unused but not deleted — can be cleaned up in a follow-up
  • BootErrorBoundary is intentionally NOT migrated as it has specialized reload-recovery logic

…back

Introduce a unified SafeBoundary component (silent/alert variants) to
replace scattered custom ErrorBoundary class components. Automatically
wraps Inspector, ContentBlock sub-components, MessageItem, and
EditorCanvas to prevent individual component crashes from propagating
to the entire app.
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Error Error Mar 26, 2026 6:30pm

Request Review

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

We've reviewed this pull request using the Sourcery rules engine

@lobehubbot
Copy link
Copy Markdown
Member

@canisminor1990 @ONLY-yours - This refactor introduces a unified SafeBoundary error boundary component, touching EditorCanvas, UI components, conversation messages, and plugin/tool rendering. Please take a look.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.76%. Comparing base (9e9ba3e) to head (5e02594).
⚠️ Report is 6 commits behind head on canary.

Additional details and impacted files
@@           Coverage Diff           @@
##           canary   #13321   +/-   ##
=======================================
  Coverage   66.76%   66.76%           
=======================================
  Files        1888     1888           
  Lines      151436   151436           
  Branches    14507    14509    +2     
=======================================
+ Hits       101109   101111    +2     
+ Misses      50215    50213    -2     
  Partials      112      112           
Flag Coverage Δ
app 58.20% <100.00%> (+<0.01%) ⬆️
database 96.64% <ø> (ø)
packages/agent-runtime 89.61% <ø> (ø)
packages/context-engine 83.22% <ø> (ø)
packages/conversation-flow 92.36% <ø> (ø)
packages/file-loaders 87.02% <ø> (ø)
packages/memory-user-memory 66.68% <ø> (ø)
packages/model-bank 99.85% <ø> (ø)
packages/model-runtime 84.48% <ø> (ø)
packages/prompts 67.76% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/utils 90.41% <ø> (ø)
packages/web-crawler 88.82% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 66.07% <ø> (ø)
Services 49.56% <ø> (ø)
Server 67.37% <ø> (+<0.01%) ⬆️
Libs 51.06% <ø> (ø)
Utils 91.01% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Innei Innei merged commit 3d592ca into canary Mar 27, 2026
30 of 31 checks passed
@Innei Innei deleted the feat/generic-error-boundary branch March 27, 2026 07:10
@lobehubbot
Copy link
Copy Markdown
Member

❤️ Great PR @Innei ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.

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