Home / Function/ render() — astro Function Reference

render() — astro Function Reference

Architecture documentation for the render() function in slots.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  cac0efcf_85fe_9d2e_7466_f43eee3dc68d["render()"]
  39243d9c_ec83_60a3_c7ca_6ad834992ebb["Slots"]
  cac0efcf_85fe_9d2e_7466_f43eee3dc68d -->|defined in| 39243d9c_ec83_60a3_c7ca_6ad834992ebb
  9edf48b2_00a8_f415_dc4e_dcdd75514521["has()"]
  cac0efcf_85fe_9d2e_7466_f43eee3dc68d -->|calls| 9edf48b2_00a8_f415_dc4e_dcdd75514521
  40c2c428_0b31_de95_a2fe_3cd1817132f9["getFunctionExpression()"]
  cac0efcf_85fe_9d2e_7466_f43eee3dc68d -->|calls| 40c2c428_0b31_de95_a2fe_3cd1817132f9
  style cac0efcf_85fe_9d2e_7466_f43eee3dc68d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/render/slots.ts lines 49–83

	public async render(name: string, args: any[] = []) {
		if (!this.#slots || !this.has(name)) return;

		const result = this.#result;
		if (!Array.isArray(args)) {
			this.#logger.warn(
				null,
				`Expected second parameter to be an array, received a ${typeof args}. If you're trying to pass an array as a single argument and getting unexpected results, make sure you're passing your array as a item of an array. Ex: Astro.slots.render('default', [["Hello", "World"]])`,
			);
		} else if (args.length > 0) {
			const slotValue = this.#slots[name];
			const component = typeof slotValue === 'function' ? await slotValue(result) : await slotValue;

			// Astro
			const expression = getFunctionExpression(component);
			if (expression) {
				const slot = async () =>
					typeof expression === 'function' ? expression(...args) : expression;
				return await renderSlotToString(result, slot).then((res) => {
					return res;
				});
			}
			// JSX
			if (typeof component === 'function') {
				return await renderJSX(result, (component as any)(...args)).then((res) =>
					res != null ? String(res) : res,
				);
			}
		}

		const content = await renderSlotToString(result, this.#slots[name]);
		const outHTML = chunkToString(result, content);

		return outHTML;
	}

Domain

Subdomains

Frequently Asked Questions

What does render() do?
render() is a function in the astro codebase, defined in packages/astro/src/core/render/slots.ts.
Where is render() defined?
render() is defined in packages/astro/src/core/render/slots.ts at line 49.
What does render() call?
render() calls 2 function(s): getFunctionExpression, has.

Analyze Your Own Codebase

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

Try Supermodel Free