stringifyChunk() — astro Function Reference
Architecture documentation for the stringifyChunk() function in common.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD fb23a8c0_fa0b_aec3_d37d_c4f2ea9dc8da["stringifyChunk()"] dc345517_d883_7bce_edfa_c6cabf28094d["common.ts"] fb23a8c0_fa0b_aec3_d37d_c4f2ea9dc8da -->|defined in| dc345517_d883_7bce_edfa_c6cabf28094d 14cf8046_9f49_caf9_66a5_a588c44dbb8d["chunkToString()"] 14cf8046_9f49_caf9_66a5_a588c44dbb8d -->|calls| fb23a8c0_fa0b_aec3_d37d_c4f2ea9dc8da 829cbefa_4c56_bedf_00ac_fa4b0752a1d7["chunkToByteArray()"] 829cbefa_4c56_bedf_00ac_fa4b0752a1d7 -->|calls| fb23a8c0_fa0b_aec3_d37d_c4f2ea9dc8da 50d20a6a_6b94_d645_ae33_fc117cb875a3["chunkToByteArrayOrString()"] 50d20a6a_6b94_d645_ae33_fc117cb875a3 -->|calls| fb23a8c0_fa0b_aec3_d37d_c4f2ea9dc8da style fb23a8c0_fa0b_aec3_d37d_c4f2ea9dc8da fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/runtime/server/render/common.ts lines 54–133
function stringifyChunk(
result: SSRResult,
chunk: string | HTMLString | SlotString | RenderInstruction,
): string {
if (isRenderInstruction(chunk)) {
const instruction = chunk;
switch (instruction.type) {
case 'directive': {
const { hydration } = instruction;
let needsHydrationScript = hydration && determineIfNeedsHydrationScript(result);
let needsDirectiveScript =
hydration && determinesIfNeedsDirectiveScript(result, hydration.directive);
if (needsHydrationScript) {
let prescripts = getPrescripts(result, 'both', hydration.directive);
return markHTMLString(prescripts);
} else if (needsDirectiveScript) {
let prescripts = getPrescripts(result, 'directive', hydration.directive);
return markHTMLString(prescripts);
} else {
return '';
}
}
case 'head': {
if (result._metadata.hasRenderedHead || result.partial) {
return '';
}
return renderAllHeadContent(result);
}
case 'maybe-head': {
if (result._metadata.hasRenderedHead || result._metadata.headInTree || result.partial) {
return '';
}
return renderAllHeadContent(result);
}
case 'renderer-hydration-script': {
const { rendererSpecificHydrationScripts } = result._metadata;
const { rendererName } = instruction;
if (!rendererSpecificHydrationScripts.has(rendererName)) {
rendererSpecificHydrationScripts.add(rendererName);
return instruction.render();
}
return '';
}
case 'server-island-runtime': {
if (result._metadata.hasRenderedServerIslandRuntime) {
return '';
}
result._metadata.hasRenderedServerIslandRuntime = true;
return renderServerIslandRuntime();
}
case 'script': {
const { id, content } = instruction;
if (result._metadata.renderedScripts.has(id)) {
return '';
}
result._metadata.renderedScripts.add(id);
return content;
}
default: {
throw new Error(`Unknown chunk type: ${(chunk as any).type}`);
}
}
} else if (chunk instanceof Response) {
return '';
} else if (isSlotString(chunk as string)) {
let out = '';
const c = chunk as SlotString;
if (c.instructions) {
for (const instr of c.instructions) {
out += stringifyChunk(result, instr);
}
}
out += chunk.toString();
return out;
}
return chunk.toString();
}
Domain
Subdomains
Source
Frequently Asked Questions
What does stringifyChunk() do?
stringifyChunk() is a function in the astro codebase, defined in packages/astro/src/runtime/server/render/common.ts.
Where is stringifyChunk() defined?
stringifyChunk() is defined in packages/astro/src/runtime/server/render/common.ts at line 54.
What calls stringifyChunk()?
stringifyChunk() is called by 3 function(s): chunkToByteArray, chunkToByteArrayOrString, chunkToString.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free