Skip to content

Commit f5ac97c

Browse files
committed
fix: avoid errors on unmounted Suspense components
1 parent 42dba32 commit f5ac97c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/core/src/useStateObservable.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
DefaultedStateObservable,
33
liftSuspense,
4+
NoSubscribersError,
45
StateObservable,
56
StatePromise,
67
SUSPENSE,
@@ -26,7 +27,11 @@ export const useStateObservable = <O>(
2627
if (!callbackRef.current) {
2728
const getValue = (src: StateObservable<O>) => {
2829
const result = src.getValue()
29-
if (result instanceof StatePromise) throw result
30+
if (result instanceof StatePromise)
31+
throw result.catch((e) => {
32+
if (e instanceof NoSubscribersError) return e
33+
throw e
34+
})
3035
return result as any
3136
}
3237

0 commit comments

Comments
 (0)