Home / Class/ ServerIslandComponent Class — astro Architecture

ServerIslandComponent Class — astro Architecture

Architecture documentation for the ServerIslandComponent class in server-islands.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  4d35505e_dd90_7891_e19a_4730ce8738e2["ServerIslandComponent"]
  cdac2309_6b88_4855_a8b7_92ab5e67a65d["server-islands.ts"]
  4d35505e_dd90_7891_e19a_4730ce8738e2 -->|defined in| cdac2309_6b88_4855_a8b7_92ab5e67a65d
  c94fa300_4779_3daf_2c89_ad17493c5011["constructor()"]
  4d35505e_dd90_7891_e19a_4730ce8738e2 -->|method| c94fa300_4779_3daf_2c89_ad17493c5011
  23261a74_abb4_3261_95d8_53855faaa9a7["init()"]
  4d35505e_dd90_7891_e19a_4730ce8738e2 -->|method| 23261a74_abb4_3261_95d8_53855faaa9a7
  274139e4_ac9d_689e_6946_beb93471fb84["render()"]
  4d35505e_dd90_7891_e19a_4730ce8738e2 -->|method| 274139e4_ac9d_689e_6946_beb93471fb84
  40c8a937_04ef_474d_1b80_d53166403f39["getComponentPath()"]
  4d35505e_dd90_7891_e19a_4730ce8738e2 -->|method| 40c8a937_04ef_474d_1b80_d53166403f39
  44e4d19a_3d65_b894_526b_74c6427949a1["getComponentExport()"]
  4d35505e_dd90_7891_e19a_4730ce8738e2 -->|method| 44e4d19a_3d65_b894_526b_74c6427949a1
  67cf42ad_a2b9_a680_47b7_c763313dc5b0["getHostId()"]
  4d35505e_dd90_7891_e19a_4730ce8738e2 -->|method| 67cf42ad_a2b9_a680_47b7_c763313dc5b0
  bcfee27a_2e68_b340_ffdb_f47378299d82["getIslandContent()"]
  4d35505e_dd90_7891_e19a_4730ce8738e2 -->|method| bcfee27a_2e68_b340_ffdb_f47378299d82

Relationship Graph

Source Code

packages/astro/src/runtime/server/render/server-islands.ts lines 55–226

export class ServerIslandComponent {
	result: SSRResult;
	props: Record<string | number, any>;
	slots: ComponentSlots;
	displayName: string;
	hostId: string | undefined;
	islandContent: string | undefined;
	componentPath: string | undefined;
	componentExport: string | undefined;
	componentId: string | undefined;
	constructor(
		result: SSRResult,
		props: Record<string | number, any>,
		slots: ComponentSlots,
		displayName: string,
	) {
		this.result = result;
		this.props = props;
		this.slots = slots;
		this.displayName = displayName;
	}

	async init(): Promise<ThinHead> {
		const content = await this.getIslandContent();

		if (this.result.cspDestination) {
			this.result._metadata.extraScriptHashes.push(
				await generateCspDigest(SERVER_ISLAND_REPLACER, this.result.cspAlgorithm),
			);
			const contentDigest = await generateCspDigest(content, this.result.cspAlgorithm);
			this.result._metadata.extraScriptHashes.push(contentDigest);
		}

		return createThinHead();
	}
	async render(destination: RenderDestination) {
		const hostId = await this.getHostId();
		const islandContent = await this.getIslandContent();
		destination.write(createRenderInstruction({ type: 'server-island-runtime' }));
		destination.write('<!--[if astro]>server-island-start<![endif]-->');
		// Render the slots
		for (const name in this.slots) {
			if (name === 'fallback') {
				await renderChild(destination, this.slots.fallback(this.result));
			}
		}
		destination.write(
			`<script type="module" data-astro-rerun data-island-id="${hostId}">${islandContent}</script>`,
		);
	}

	getComponentPath(): string {
		if (this.componentPath) {
			return this.componentPath;
		}
		const componentPath = this.props['server:component-path'];
		if (!componentPath) {
			throw new Error(`Could not find server component path`);
		}
		this.componentPath = componentPath;
		return componentPath;
	}

	getComponentExport(): string {
		if (this.componentExport) {
			return this.componentExport;
		}
		const componentExport = this.props['server:component-export'];
		if (!componentExport) {
			throw new Error(`Could not find server component export`);
		}
		this.componentExport = componentExport;
		return componentExport;
	}

	async getHostId() {
		if (!this.hostId) {
			this.hostId = await crypto.randomUUID();
		}
		return this.hostId;
	}

Domain

Frequently Asked Questions

What is the ServerIslandComponent class?
ServerIslandComponent is a class in the astro codebase, defined in packages/astro/src/runtime/server/render/server-islands.ts.
Where is ServerIslandComponent defined?
ServerIslandComponent is defined in packages/astro/src/runtime/server/render/server-islands.ts at line 55.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free