getIslandContent() — astro Function Reference
Architecture documentation for the getIslandContent() function in server-islands.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD bcfee27a_2e68_b340_ffdb_f47378299d82["getIslandContent()"] 4d35505e_dd90_7891_e19a_4730ce8738e2["ServerIslandComponent"] bcfee27a_2e68_b340_ffdb_f47378299d82 -->|defined in| 4d35505e_dd90_7891_e19a_4730ce8738e2 23261a74_abb4_3261_95d8_53855faaa9a7["init()"] 23261a74_abb4_3261_95d8_53855faaa9a7 -->|calls| bcfee27a_2e68_b340_ffdb_f47378299d82 274139e4_ac9d_689e_6946_beb93471fb84["render()"] 274139e4_ac9d_689e_6946_beb93471fb84 -->|calls| bcfee27a_2e68_b340_ffdb_f47378299d82 40c8a937_04ef_474d_1b80_d53166403f39["getComponentPath()"] bcfee27a_2e68_b340_ffdb_f47378299d82 -->|calls| 40c8a937_04ef_474d_1b80_d53166403f39 44e4d19a_3d65_b894_526b_74c6427949a1["getComponentExport()"] bcfee27a_2e68_b340_ffdb_f47378299d82 -->|calls| 44e4d19a_3d65_b894_526b_74c6427949a1 67cf42ad_a2b9_a680_47b7_c763313dc5b0["getHostId()"] bcfee27a_2e68_b340_ffdb_f47378299d82 -->|calls| 67cf42ad_a2b9_a680_47b7_c763313dc5b0 212eecb4_260f_98c8_008f_3b0de43572a3["createSearchParams()"] bcfee27a_2e68_b340_ffdb_f47378299d82 -->|calls| 212eecb4_260f_98c8_008f_3b0de43572a3 fe3f237c_cf8c_64f2_271c_ce1dd0ad62fc["isWithinURLLimit()"] bcfee27a_2e68_b340_ffdb_f47378299d82 -->|calls| fe3f237c_cf8c_64f2_271c_ce1dd0ad62fc 6c5733f4_136d_23b4_f2f7_d221719c799a["safeJsonStringify()"] bcfee27a_2e68_b340_ffdb_f47378299d82 -->|calls| 6c5733f4_136d_23b4_f2f7_d221719c799a style bcfee27a_2e68_b340_ffdb_f47378299d82 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/runtime/server/render/server-islands.ts lines 137–225
async getIslandContent() {
if (this.islandContent) {
return this.islandContent;
}
const componentPath = this.getComponentPath();
const componentExport = this.getComponentExport();
let componentId = this.result.serverIslandNameMap.get(componentPath);
if (!componentId) {
throw new Error(`Could not find server component name ${componentPath}`);
}
// Remove internal props
for (const key of Object.keys(this.props)) {
if (internalProps.has(key)) {
delete this.props[key];
}
}
// Render the slots
const renderedSlots: Record<string, string> = {};
for (const name in this.slots) {
if (name !== 'fallback') {
const content = await renderSlotToString(this.result, this.slots[name]);
renderedSlots[name] = content.toString();
}
}
const key = await this.result.key;
// Encrypt componentExport
const componentExportEncrypted = await encryptString(key, componentExport);
const propsEncrypted =
Object.keys(this.props).length === 0
? ''
: await encryptString(key, JSON.stringify(this.props));
// Encrypt slots
const slotsEncrypted =
Object.keys(renderedSlots).length === 0
? ''
: await encryptString(key, JSON.stringify(renderedSlots));
const hostId = await this.getHostId();
const slash = this.result.base.endsWith('/') ? '' : '/';
let serverIslandUrl = `${this.result.base}${slash}_server-islands/${componentId}${this.result.trailingSlash === 'always' ? '/' : ''}`;
// Determine if its safe to use a GET request
const potentialSearchParams = createSearchParams(
componentExportEncrypted,
propsEncrypted,
slotsEncrypted,
);
const useGETRequest = isWithinURLLimit(serverIslandUrl, potentialSearchParams);
if (useGETRequest) {
serverIslandUrl += '?' + potentialSearchParams.toString();
this.result._metadata.extraHead.push(
markHTMLString(
`<link rel="preload" as="fetch" href="${serverIslandUrl}" crossorigin="anonymous">`,
),
);
}
// Get adapter headers for inline script
const adapterHeaders = this.result.internalFetchHeaders || {};
const headersJson = safeJsonStringify(adapterHeaders);
const method = useGETRequest
? // GET request
`const headers = new Headers(${headersJson});
let response = await fetch('${serverIslandUrl}', { headers });`
: // POST request
`let data = {
encryptedComponentExport: ${safeJsonStringify(componentExportEncrypted)},
encryptedProps: ${safeJsonStringify(propsEncrypted)},
encryptedSlots: ${safeJsonStringify(slotsEncrypted)},
};
const headers = new Headers({ 'Content-Type': 'application/json', ...${headersJson} });
let response = await fetch('${serverIslandUrl}', {
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does getIslandContent() do?
getIslandContent() is a function in the astro codebase, defined in packages/astro/src/runtime/server/render/server-islands.ts.
Where is getIslandContent() defined?
getIslandContent() is defined in packages/astro/src/runtime/server/render/server-islands.ts at line 137.
What does getIslandContent() call?
getIslandContent() calls 6 function(s): createSearchParams, getComponentExport, getComponentPath, getHostId, isWithinURLLimit, safeJsonStringify.
What calls getIslandContent()?
getIslandContent() is called by 2 function(s): init, render.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free