From 6d52c4ee313adda70aa87a3c0f7e0014f04e521c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Fri, 7 Nov 2025 01:13:50 +0100 Subject: [PATCH] Add ErrorObserver handle --- packages/effect-fc/src/Async.ts | 5 +++-- packages/effect-fc/src/Component.ts | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/effect-fc/src/Async.ts b/packages/effect-fc/src/Async.ts index a0dba11..0a63777 100644 --- a/packages/effect-fc/src/Async.ts +++ b/packages/effect-fc/src/Async.ts @@ -2,6 +2,7 @@ import { Effect, Function, Predicate, Runtime, Scope } from "effect" import * as React from "react" import * as Component from "./Component.js" +import * as ErrorObserver from "./ErrorObserver.js" export const TypeId: unique symbol = Symbol.for("@effect-fc/Async/Async") @@ -31,10 +32,10 @@ const SuspenseProto = Object.freeze({ return ({ fallback, name, ...props }: Async.Props) => { const promise = Runtime.runPromise(runtimeRef.current)( - Effect.andThen( + ErrorObserver.handle(Effect.andThen( Component.useScope([], this), scope => Effect.provideService(this.body(props as P), Scope.Scope, scope), - ) + )) ) return React.createElement( diff --git a/packages/effect-fc/src/Component.ts b/packages/effect-fc/src/Component.ts index 38d8bd0..921ccff 100644 --- a/packages/effect-fc/src/Component.ts +++ b/packages/effect-fc/src/Component.ts @@ -2,6 +2,7 @@ /** biome-ignore-all lint/complexity/useArrowFunction: necessary for class prototypes */ import { Context, type Duration, Effect, Effectable, Equivalence, ExecutionStrategy, Exit, Fiber, Function, HashMap, Layer, ManagedRuntime, Option, Predicate, Ref, Runtime, Scope, Tracer, type Utils } from "effect" import * as React from "react" +import * as ErrorObserver from "./ErrorObserver.js" import { Memoized } from "./index.js" @@ -75,10 +76,10 @@ const ComponentProto = Object.freeze({ runtimeRef: React.RefObject>>, ) { return (props: P) => Runtime.runSync(runtimeRef.current)( - Effect.andThen( + ErrorObserver.handle(Effect.andThen( useScope([], this), scope => Effect.provideService(this.body(props), Scope.Scope, scope), - ) + )) ) }, } as const) @@ -547,14 +548,15 @@ const runReactEffect = ( () => { switch (options?.finalizerExecutionMode ?? "fork") { case "sync": - Runtime.runSync(runtime)(Scope.close(scope, Exit.void)) + Runtime.runSync(runtime)(ErrorObserver.handle(Scope.close(scope, Exit.void))) break case "fork": - Runtime.runFork(runtime)(Scope.close(scope, Exit.void)) + Runtime.runFork(runtime)(ErrorObserver.handle(Scope.close(scope, Exit.void))) break } } ), + ErrorObserver.handle, Runtime.runSync(runtime), )