Skip to content

fix(hooks): propagate errors in useAsyncCallback to the React error boundary#612

Draft
Just-Insane wants to merge 2 commits intoSableClient:devfrom
Just-Insane:fix/async-callback-rejections
Draft

fix(hooks): propagate errors in useAsyncCallback to the React error boundary#612
Just-Insane wants to merge 2 commits intoSableClient:devfrom
Just-Insane:fix/async-callback-rejections

Conversation

@Just-Insane
Copy link
Copy Markdown
Contributor

Related to closed PR #548 (fix/media-error-handling), which was split into smaller focused PRs.

Description

useAsyncCallback was silently swallowing unhandled rejections from async callbacks. React's error boundary never received them, so errors were invisible to users and the UI could be left in a stuck loading state indefinitely. This fix wraps internal invocations so unhandled rejections are re-thrown on the next tick and surface to the nearest React error boundary.

Fixes #

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

AI disclosure:

  • Partially AI assisted (clarify which code was AI assisted and briefly explain what it does).
  • Fully AI generated (explain what all the generated code does in moderate detail).

The error propagation wrapper in useAsyncCallback was partially AI assisted. I reviewed the boundary behaviour and verified errors surface correctly rather than being swallowed.

Wrap the inner callback with a no-op .catch() so fire-and-forget call
sites (e.g. loadSrc in useEffect) do not produce 'Uncaught (in promise)'
console warnings. The promise is still returned and re-thrown for callers
that await or chain, so intentional error handling is unaffected.
@Just-Insane Just-Insane requested review from 7w1 and hazre as code owners March 31, 2026 18:43
@Just-Insane Just-Insane marked this pull request as draft March 31, 2026 20:13
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.

1 participant