-
Notifications
You must be signed in to change notification settings - Fork 46
fix(hooks): propagate errors in useAsyncCallback to the React error boundary #612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 3 commits
7c28e2b
e977b36
792fd83
6ab811d
a552488
58ae0eb
ff747a3
024401b
c40d5c8
a1aff9e
53a3aff
8366173
02ced60
5090322
bbb31fc
34b1b4d
3edf610
37b6af1
2ac47de
68fdb85
6aa40cc
698bda0
02e9d7a
2ab3bcd
2cf9895
bc6b57d
94fae05
f68ee8e
5c4fe1c
25258f1
bfee547
6df45a4
a5f35e9
201e230
04d59f5
73beb8c
4a6289e
85a7f6d
918f2d7
bc58d6e
add3987
718210f
dfebd09
a53112f
d9a6656
117949f
f726833
2a9fa52
68d35f9
d327e19
426ef74
53930d4
d9a10cb
6361351
3fcd6c1
76e0c49
ff1b207
bccc48f
2964e89
b3304bb
06c9810
ac899aa
dcb56f6
e848f3a
a294d16
2eeaa43
a4751d4
1ad6b03
12888d9
ac4e5b4
755588b
49a98b3
6a27271
35acb82
4404e84
8f69b61
1ba25f8
c178b77
ac75284
c7d44d8
ce458fb
f7c7fee
b86b5de
a71bdab
ca97c9b
594fda0
31441ad
d8da869
4a15b74
b0a8091
264e4ab
878f2fc
e4d24b2
05fa657
a2d5683
4eeaa38
260a4e8
9036ec9
db9c1a4
216aa6a
b848ac2
ec10020
20376bf
581f2ce
86701ca
4b29d29
2202bec
cd5192b
8cdf36a
e5bdd7c
3f03876
4cb00a5
0231581
1f9dae9
9d9dce7
29e4076
12b379e
2b39316
69179c1
9ebd8d3
da4a07b
d7fd640
82bde31
e0eb8ab
7680897
850e025
7bb22d2
42c59ad
cb24302
3149a37
56de896
ca65cef
cbd653e
8fee117
809a9bb
dc21873
8c3c0e7
71138ec
ad50ff1
83031b2
bd31c97
17ccebd
1392b77
399418b
700ea1e
272eff3
7579368
f8986c1
5f41827
111d57e
b60c2dc
77f806a
68d653d
5cc0da5
e1adb09
3bea590
fd9e007
ef01765
1e15b4b
164a6b6
143e012
910d13a
67b1a11
a7f8c1a
ce68c59
84fadae
c4ca608
157df81
be5bcd2
1fc16ae
0491959
f6a7cd7
2ef5386
afc2b49
6b89dc6
d863695
52bbbc6
ff50906
f95c396
39e25e3
e12a4b0
ead2bb1
e6e6048
449de0a
b851f43
a374275
21f0f39
1e483cc
344536c
0b2b720
2144458
90aee8c
88840d7
93ebd90
4896b70
aeeb6ec
0338a34
27ac950
6da27d6
88b7f05
15911d4
8054b69
ffd63b5
3484ec5
953c716
0b9b0fd
95c9993
f99f9ba
1eb3847
5ba7bd7
022649c
dbef5d9
a8b17b8
807d00f
13d1baf
1c50d87
708a76a
3e373ce
d570e4b
b2b043c
65b45ba
9199a87
d82f8e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| default: patch | ||
| --- | ||
|
|
||
| Fix unhandled promise rejections in useAsyncCallback by propagating errors to the error boundary | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -73,6 +73,9 @@ export const useAsync = <TData, TError, TArgs extends unknown[]>( | |||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| // Re-throw so .then()/.catch() callers see the rejection and success | ||||||||||||||||||||||||||||
| // handlers are skipped. Fire-and-forget unhandled-rejection warnings are | ||||||||||||||||||||||||||||
| // suppressed at the useAsyncCallback level via a no-op .catch wrapper. | ||||||||||||||||||||||||||||
| throw e; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -102,7 +105,19 @@ export const useAsyncCallback = <TData, TError, TArgs extends unknown[]>( | |||||||||||||||||||||||||||
| status: AsyncStatus.Idle, | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const callback = useAsync(asyncCallback, setState); | ||||||||||||||||||||||||||||
| const innerCallback = useAsync(asyncCallback, setState); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Re-throw preserves rejection for callers that await/chain; the no-op .catch | ||||||||||||||||||||||||||||
| // suppresses "Uncaught (in promise)" for fire-and-forget call sites (e.g. | ||||||||||||||||||||||||||||
| // loadSrc() in a useEffect) without swallowing the error from intentional callers. | ||||||||||||||||||||||||||||
| const callback = useCallback( | ||||||||||||||||||||||||||||
| (...args: TArgs): Promise<TData> => { | ||||||||||||||||||||||||||||
| const p = innerCallback(...args); | ||||||||||||||||||||||||||||
| p.catch(() => {}); | ||||||||||||||||||||||||||||
| return p; | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| [innerCallback] | ||||||||||||||||||||||||||||
| ) as AsyncCallback<TArgs, TData>; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
Comment on lines
+109
to
121
|
||||||||||||||||||||||||||||
| // Re-throw preserves rejection for callers that await/chain; the no-op .catch | |
| // suppresses "Uncaught (in promise)" for fire-and-forget call sites (e.g. | |
| // loadSrc() in a useEffect) without swallowing the error from intentional callers. | |
| const callback = useCallback( | |
| (...args: TArgs): Promise<TData> => { | |
| const p = innerCallback(...args); | |
| p.catch(() => {}); | |
| return p; | |
| }, | |
| [innerCallback] | |
| ) as AsyncCallback<TArgs, TData>; | |
| const callback = innerCallback as AsyncCallback<TArgs, TData>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changeset entry claims errors are propagated “to the error boundary”, but the current implementation adds a no-op
.catchthat suppresses unhandled promise rejections (and React error boundaries don’t catch async rejections anyway). Please align the changeset wording with the actual behavior, or adjust the implementation to truly route unhandled async errors into the app’s chosen error-boundary/reporting mechanism.