extractDirectives() — astro Function Reference
Architecture documentation for the extractDirectives() function in hydration.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 54167949_f851_104a_899f_c6188a7177dc["extractDirectives()"] 5c9b16ff_599b_b1b0_fd4a_a24ff528fd5b["hydration.ts"] 54167949_f851_104a_899f_c6188a7177dc -->|defined in| 5c9b16ff_599b_b1b0_fd4a_a24ff528fd5b style 54167949_f851_104a_899f_c6188a7177dc fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/runtime/server/hydration.ts lines 35–115
export function extractDirectives(
inputProps: Props,
clientDirectives: SSRResult['clientDirectives'],
): ExtractedProps {
let extracted: ExtractedProps = {
isPage: false,
hydration: null,
props: {},
propsWithoutTransitionAttributes: {},
};
for (const [key, value] of Object.entries(inputProps)) {
if (key.startsWith('server:')) {
if (key === 'server:root') {
extracted.isPage = true;
}
}
if (key.startsWith('client:')) {
if (!extracted.hydration) {
extracted.hydration = {
directive: '',
value: '',
componentUrl: '',
componentExport: { value: '' },
};
}
switch (key) {
case 'client:component-path': {
extracted.hydration.componentUrl = value;
break;
}
case 'client:component-export': {
extracted.hydration.componentExport.value = value;
break;
}
// This is a special prop added to prove that the client hydration method
// was added statically.
case 'client:component-hydration': {
break;
}
case 'client:display-name': {
break;
}
default: {
extracted.hydration.directive = key.split(':')[1];
extracted.hydration.value = value;
// throw an error if an invalid hydration directive was provided
if (!clientDirectives.has(extracted.hydration.directive)) {
const hydrationMethods = Array.from(clientDirectives.keys())
.map((d) => `client:${d}`)
.join(', ');
throw new Error(
`Error: invalid hydration directive "${key}". Supported hydration methods: ${hydrationMethods}`,
);
}
// throw an error if the query wasn't provided for client:media
if (
extracted.hydration.directive === 'media' &&
typeof extracted.hydration.value !== 'string'
) {
throw new AstroError(AstroErrorData.MissingMediaQueryDirective);
}
break;
}
}
} else {
extracted.props[key] = value;
if (!transitionDirectivesToCopyOnIsland.includes(key)) {
extracted.propsWithoutTransitionAttributes[key] = value;
}
}
}
for (const sym of Object.getOwnPropertySymbols(inputProps)) {
extracted.props[sym] = inputProps[sym];
extracted.propsWithoutTransitionAttributes[sym] = inputProps[sym];
}
return extracted;
}
Domain
Subdomains
Source
Frequently Asked Questions
What does extractDirectives() do?
extractDirectives() is a function in the astro codebase, defined in packages/astro/src/runtime/server/hydration.ts.
Where is extractDirectives() defined?
extractDirectives() is defined in packages/astro/src/runtime/server/hydration.ts at line 35.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free