Skip to content

runInContext

Run fn in a fresh child Context (just like effect) but without a tracking ReactiveEffect wrapper. Use this when the caller knows the body does not establish reactive subscriptions at its top level (e.g. it wraps its only reactive reads in untrack() or function children) — typically for component-invocation plumbing where the outer “effect” never re-fires.

Compared to effect:

  • No vueEffect allocation, no scheduler binding.
  • The body runs synchronously to completion exactly once.
  • Disposables registered via onCleanup inside fn (or its descendants) are still registered on the new context, and disposed via the parent context’s cleanup chain.

Returns the value returned by fn.

import { runInContext } from "@alloy-js/core";
function runInContext<T>(fn: () => T): T;
fn() => T

T