renderProgressive method
Render a component tree progressively via a stream of partial trees (FR-003 acceptance 3 — "intermediate nodes arrive before the full tree completes").
Each partial is emitted as a UiRenderEventRender with isPartial: true
(except the last, which is isPartial: false). The final view returned
by the future is also recorded in the mission trace.
Implementation
Stream<RenderedView> renderProgressive(
Stream<UiNode> partials, {
String? hint,
}) async* {
final missionType = _activeMissionType;
if (missionType == null) {
throw NoActiveMissionException();
}
final schema = vocabularyNarrowing(
missionType,
baseSchema,
config: narrowingConfig,
);
final viewId = _idGenerator();
RenderedView? lastPartial;
await for (final partial in partials) {
final result = schema.validate(partial);
if (!result.valid) {
channel.emitError(UiRenderValidationException(result));
// Drop any partial we stored and close the view so the host does not
// wait forever for a Done event.
_views.remove(viewId);
channel.emitDone(viewId);
return;
}
final contentHash = computeContentHash(partial);
final view = RenderedView(
viewId: viewId,
tree: partial,
schemaVersion: schema.schemaVersion,
contentHash: contentHash,
hint: hint,
);
lastPartial = view;
_views[viewId] = view;
channel.emitRender(view, isPartial: true);
yield view;
}
// Always close the view (even for an empty partials stream) so the host
// never blocks awaiting a Done event.
final finalView = lastPartial;
if (finalView != null) {
channel.emitRender(finalView, isPartial: false);
recorder.record(finalView, missionType: missionType);
}
channel.emitDone(viewId);
}