RenderTemplateResult Class — astro Architecture
Architecture documentation for the RenderTemplateResult class in render-template.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD a09367a5_8fe9_7718_47bb_f1d1ba04f076["RenderTemplateResult"] 88076124_0268_757a_e929_c3261d00db3a["render-template.ts"] a09367a5_8fe9_7718_47bb_f1d1ba04f076 -->|defined in| 88076124_0268_757a_e929_c3261d00db3a fab9733c_248e_c1ed_7ba2_77cedf7be6a3["constructor()"] a09367a5_8fe9_7718_47bb_f1d1ba04f076 -->|method| fab9733c_248e_c1ed_7ba2_77cedf7be6a3 852c9565_5de5_4aa5_caaa_2b9cb89db9e3["render()"] a09367a5_8fe9_7718_47bb_f1d1ba04f076 -->|method| 852c9565_5de5_4aa5_caaa_2b9cb89db9e3
Relationship Graph
Source Code
packages/astro/src/runtime/server/render/astro/render-template.ts lines 11–75
export class RenderTemplateResult {
public [renderTemplateResultSym] = true;
private htmlParts: TemplateStringsArray;
public expressions: any[];
private error: Error | undefined;
constructor(htmlParts: TemplateStringsArray, expressions: unknown[]) {
this.htmlParts = htmlParts;
this.error = undefined;
this.expressions = expressions.map((expression) => {
// Wrap Promise expressions so we can catch errors
// There can only be 1 error that we rethrow from an Astro component,
// so this keeps track of whether or not we have already done so.
if (isPromise(expression)) {
return Promise.resolve(expression).catch((err) => {
if (!this.error) {
this.error = err;
throw err;
}
});
}
return expression;
});
}
render(destination: RenderDestination): void | Promise<void> {
// Render all expressions eagerly and in parallel
const flushers = this.expressions.map((exp) => {
return createBufferedRenderer(destination, (bufferDestination) => {
// Skip render if falsy, except the number 0
if (exp || exp === 0) {
return renderChild(bufferDestination, exp);
}
});
});
let i = 0;
const iterate = (): void | Promise<void> => {
while (i < this.htmlParts.length) {
const html = this.htmlParts[i];
const flusher = flushers[i];
// increment here due to potential return in
// Promise scenario
i++;
if (html) {
// only write non-empty strings
destination.write(markHTMLString(html));
}
if (flusher) {
const result = flusher.flush();
if (isPromise(result)) {
return result.then(iterate);
}
}
}
};
return iterate();
}
}
Domain
Source
Frequently Asked Questions
What is the RenderTemplateResult class?
RenderTemplateResult is a class in the astro codebase, defined in packages/astro/src/runtime/server/render/astro/render-template.ts.
Where is RenderTemplateResult defined?
RenderTemplateResult is defined in packages/astro/src/runtime/server/render/astro/render-template.ts at line 11.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free