ssr method
void
ssr(
- String path,
- BloomNode builder(
- BloomRequest request
- HeadManager head(
- BloomRequest request
- String layout(
- String bodyHtml,
- HeadManager? head
- List<
BloomMiddleware> middlewares = const [],
Mounts a Server-Side Rendered (SSR) endpoint within this group.
Each request runs in its own isolated BloomQueryScope (issue #31), so concurrent renders sharing one isolate never share private query caches, in-flight deduplication, invalidations, or dehydration snapshots. The scope is disposed automatically on success or error.
Implementation
void ssr(
String path,
BloomNode Function(BloomRequest request) builder, {
HeadManager Function(BloomRequest request)? head,
String Function(String bodyHtml, HeadManager? head)? layout,
List<BloomMiddleware> middlewares = const [],
}) {
get(path, (request) async {
return BloomData.withRequestScope((scope) {
final node = BloomData.runWithScope(scope, () => builder(request));
final bodyHtml = renderToHtmlInScope(node, scope);
final headManager =
head == null ? null : BloomData.runWithScope(scope, () => head(request));
final String fullHtml;
if (layout != null) {
fullHtml = layout(bodyHtml, headManager);
} else if (headManager != null) {
fullHtml = headManager.wrapDocument(bodyHtml);
} else {
fullHtml =
'<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"></head><body>$bodyHtml</body></html>';
}
return BloomResponse.html(fullHtml);
}, debugLabel: 'ssr-request');
}, middlewares: middlewares);
}