Skip to content

Commit

Permalink
fix: avoid errors on unmounted Suspense components
Browse files Browse the repository at this point in the history
  • Loading branch information
josepot committed Sep 9, 2022
1 parent 42dba32 commit f5ac97c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/core/src/useStateObservable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
DefaultedStateObservable,
liftSuspense,
NoSubscribersError,
StateObservable,
StatePromise,
SUSPENSE,
Expand All @@ -26,7 +27,11 @@ export const useStateObservable = <O>(
if (!callbackRef.current) {
const getValue = (src: StateObservable<O>) => {
const result = src.getValue()
if (result instanceof StatePromise) throw result
if (result instanceof StatePromise)
throw result.catch((e) => {
if (e instanceof NoSubscribersError) return e
throw e
})
return result as any
}

Expand Down

0 comments on commit f5ac97c

Please sign in to comment.