Home / Function/ preload() — astro Function Reference

preload() — astro Function Reference

Architecture documentation for the preload() function in pipeline.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  0f5bfc9a_beba_920f_ec4e_e897a3448a53["preload()"]
  91572b20_ae8c_d5b0_82aa_5914d1622215["RunnablePipeline"]
  0f5bfc9a_beba_920f_ec4e_e897a3448a53 -->|defined in| 91572b20_ae8c_d5b0_82aa_5914d1622215
  ddcb40c7_1fe7_8127_0dcf_33d7e687f835["getComponentByRoute()"]
  ddcb40c7_1fe7_8127_0dcf_33d7e687f835 -->|calls| 0f5bfc9a_beba_920f_ec4e_e897a3448a53
  style 0f5bfc9a_beba_920f_ec4e_e897a3448a53 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/vite-plugin-app/pipeline.ts lines 164–196

	async preload(routeData: RouteData, filePath: URL) {
		if (routeIsRedirect(routeData)) {
			return RedirectComponentInstance;
		}

		const { loader } = this;

		// First check built-in routes
		for (const route of this.defaultRoutes) {
			if (route.matchesComponent(filePath)) {
				return route.instance;
			}
		}

		// Important: This needs to happen first, in case a renderer provides polyfills.
		if (this.settings) {
			const renderers__ = this.settings.renderers.map((r) => loadRenderer(r, loader));
			const renderers_ = await Promise.all(renderers__);
			this.renderers = renderers_.filter((r): r is SSRLoadedRenderer => Boolean(r));
		}

		try {
			// Load the module from the Vite SSR Runtime.
			return (await loader.import(filePath.toString())) as ComponentInstance;
		} catch (error) {
			// If the error came from Markdown or CSS, we already handled it and there's no need to enhance it
			if (MarkdownError.is(error) || CSSError.is(error) || AggregateError.is(error)) {
				throw error;
			}

			throw enhanceViteSSRError({ error, filePath, loader });
		}
	}

Domain

Subdomains

Frequently Asked Questions

What does preload() do?
preload() is a function in the astro codebase, defined in packages/astro/src/vite-plugin-app/pipeline.ts.
Where is preload() defined?
preload() is defined in packages/astro/src/vite-plugin-app/pipeline.ts at line 164.
What calls preload()?
preload() is called by 1 function(s): getComponentByRoute.

Analyze Your Own Codebase

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

Try Supermodel Free