diff --git a/packages/effect-fc-next/src/ReactRuntime.ts b/packages/effect-fc-next/src/ReactRuntime.ts index 29c738a..0cee1e0 100644 --- a/packages/effect-fc-next/src/ReactRuntime.ts +++ b/packages/effect-fc-next/src/ReactRuntime.ts @@ -46,11 +46,6 @@ export namespace Provider { export const Provider = ( { runtime, children, ...suspenseProps }: Provider.Props ): React.ReactNode => { - Effect.runSync(Component.useOnChange( - () => Effect.addFinalizer(() => runtime.runtime.disposeEffect), - [runtime], - )) - const promise = React.useMemo(() => runtime.runtime.context(), [runtime]) return React.createElement( @@ -66,4 +61,12 @@ const ProviderInner = ( readonly promise: Promise> readonly children?: React.ReactNode } -): React.ReactNode => React.createElement(runtime.context, { value: React.use(promise) }, children) +): React.ReactNode => { + const context = React.use(promise) + Effect.runSyncWith(context)(Component.useOnChange( + () => Effect.addFinalizer(() => runtime.runtime.disposeEffect), + [runtime], + )) + + return React.createElement(runtime.context, { value: context }, children) +}