Async components
Estimated reading time: 2 minutesA Kita Html component can be an async function. When it is, the JSX expression evaluates
to a Promise<string> instead of a string.
Promise propagation
When any child in a component tree is async, the entire parent chain becomes async
automatically. The runtime detects promises during child concatenation and wraps the
result in Promise.all. No manual promise handling is required at intermediate levels.
This propagation is transitive. If UserCard is nested three levels deep, every ancestor
up to the root becomes a Promise<string>.
JSX.Element type
The type JSX.Element is defined as string | Promise<string>. Any component tree may
contain async components, so the type covers both cases. When you are certain that a tree
is fully synchronous, you can cast the result to string.
See design decisions for why TypeScript cannot narrow this type.
Awaiting the result
If you need the resolved HTML string, await the result. If you are passing it to a stream or to a framework integration that handles promises, you can pass the promise directly without awaiting.