AstroComponentInstance Class — astro Architecture
Architecture documentation for the AstroComponentInstance class in instance.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD c8404018_ae72_dbaf_c01d_66b8b2cbc344["AstroComponentInstance"] 1be70ad0_d3b6_9a94_47c0_3985acb68eaf["instance.ts"] c8404018_ae72_dbaf_c01d_66b8b2cbc344 -->|defined in| 1be70ad0_d3b6_9a94_47c0_3985acb68eaf beb8afb5_7437_f0dd_54a8_abfcfd0afdae["constructor()"] c8404018_ae72_dbaf_c01d_66b8b2cbc344 -->|method| beb8afb5_7437_f0dd_54a8_abfcfd0afdae 2bbe8ffe_7c37_0788_f75d_af62023ae9c3["init()"] c8404018_ae72_dbaf_c01d_66b8b2cbc344 -->|method| 2bbe8ffe_7c37_0788_f75d_af62023ae9c3 d5585077_c610_30d8_780d_3b719e68ba58["render()"] c8404018_ae72_dbaf_c01d_66b8b2cbc344 -->|method| d5585077_c610_30d8_780d_3b719e68ba58 dbd2308d_970a_d647_1e74_5bb7249bd549["renderImpl()"] c8404018_ae72_dbaf_c01d_66b8b2cbc344 -->|method| dbd2308d_970a_d647_1e74_5bb7249bd549
Relationship Graph
Source Code
packages/astro/src/runtime/server/render/astro/instance.ts lines 14–85
export class AstroComponentInstance {
[astroComponentInstanceSym] = true;
private readonly result: SSRResult;
private readonly props: ComponentProps;
private readonly slotValues: ComponentSlots;
private readonly factory: AstroComponentFactory;
private returnValue: ReturnType<AstroComponentFactory> | undefined;
constructor(
result: SSRResult,
props: ComponentProps,
slots: ComponentSlots,
factory: AstroComponentFactory,
) {
this.result = result;
this.props = props;
this.factory = factory;
this.slotValues = {};
for (const name in slots) {
// prerender the slots eagerly to make collection entries propagate styles and scripts
let didRender = false;
let value = slots[name](result);
this.slotValues[name] = () => {
// use prerendered value only once
if (!didRender) {
didRender = true;
return value;
}
// render afresh for the advanced use-case where the same slot is rendered multiple times
return slots[name](result);
};
}
}
init(result: SSRResult): AstroFactoryReturnValue | Promise<AstroFactoryReturnValue> {
if (this.returnValue !== undefined) {
return this.returnValue;
}
this.returnValue = this.factory(result, this.props, this.slotValues);
// Save the resolved value after promise is resolved for optimization
if (isPromise(this.returnValue)) {
this.returnValue
.then((resolved) => {
this.returnValue = resolved;
})
.catch(() => {
// Ignore errors and appease unhandledrejection error
});
}
return this.returnValue;
}
render(destination: RenderDestination): void | Promise<void> {
const returnValue = this.init(this.result);
if (isPromise(returnValue)) {
return returnValue.then((x) => this.renderImpl(destination, x));
}
return this.renderImpl(destination, returnValue);
}
private renderImpl(destination: RenderDestination, returnValue: AstroFactoryReturnValue) {
if (isHeadAndContent(returnValue)) {
return returnValue.content.render(destination);
} else {
return renderChild(destination, returnValue);
}
}
}
Domain
Source
Frequently Asked Questions
What is the AstroComponentInstance class?
AstroComponentInstance is a class in the astro codebase, defined in packages/astro/src/runtime/server/render/astro/instance.ts.
Where is AstroComponentInstance defined?
AstroComponentInstance is defined in packages/astro/src/runtime/server/render/astro/instance.ts at line 14.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free