runSsrRequest<T> function

Future<T> runSsrRequest<T>(
  1. FutureOr<T> body(
    1. BloomQueryScope scope
    ), {
  2. BloomQueryScope? scope,
  3. String? debugLabel,
})

Runs body in an isolated SSR request scope, disposing it afterwards.

This is the recommended per-request wrapper for native SSR servers. It covers synchronous and Future results, including errors: the owned scope is disposed exactly once on success or throw. For Stream results (streaming SSR), use runSsrRequestStream so the scope survives until the stream closes, errors, or is cancelled.

final html = await runSsrRequest((scope) async {
  BloomData.setQueryData(['user', 'current'], (_) => alice);
  final html = renderToHtml(page());
  final state = BloomData.dehydrate();
  return '$html${BloomData.dehydrateToScriptTag(state: state)}';
});

Implementation

Future<T> runSsrRequest<T>(
  FutureOr<T> Function(BloomQueryScope scope) body, {
  BloomQueryScope? scope,
  String? debugLabel,
}) =>
    BloomData.withRequestScope<T>(body,
        scope: scope, debugLabel: debugLabel ?? 'ssr-request');