Home / File/ client.ts — astro Source File

client.ts — astro Source File

Architecture documentation for client.ts, a typescript file in the astro codebase. 3 imports, 0 dependents.

File typescript CoreAstro CoreMiddleware 3 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  4c5c105d_bd09_89ab_a651_da83bf0bf0b5["client.ts"]
  d768d4dc_95e0_cf54_1925_986c1d407d73["./static-html.js"]
  4c5c105d_bd09_89ab_a651_da83bf0bf0b5 --> d768d4dc_95e0_cf54_1925_986c1d407d73
  424749a0_0df4_313e_4a43_2972786b85fe["virtual:astro:vue-app"]
  4c5c105d_bd09_89ab_a651_da83bf0bf0b5 --> 424749a0_0df4_313e_4a43_2972786b85fe
  58645bbc_6680_4e2a_38e9_3e4f34edbed5["vue"]
  4c5c105d_bd09_89ab_a651_da83bf0bf0b5 --> 58645bbc_6680_4e2a_38e9_3e4f34edbed5
  style 4c5c105d_bd09_89ab_a651_da83bf0bf0b5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { setup } from 'virtual:astro:vue-app';
import { createApp, createSSRApp, h, Suspense } from 'vue';
import StaticHtml from './static-html.js';

// keep track of already initialized apps, so we don't hydrate again for view transitions
let appMap = new WeakMap<
	HTMLElement,
	{ props: Record<string, any>; slots: Record<string, any>; component?: any }
>();

export default (element: HTMLElement) =>
	async (
		Component: any,
		props: Record<string, any>,
		slotted: Record<string, any>,
		{ client }: Record<string, string>,
	) => {
		if (!element.hasAttribute('ssr')) return;

		// Expose name on host component for Vue devtools
		const name = Component.name ? `${Component.name} Host` : undefined;
		const slots: Record<string, any> = {};
		for (const [key, value] of Object.entries(slotted)) {
			slots[key] = () => h(StaticHtml, { value, name: key === 'default' ? undefined : key });
		}

		const isHydrate = client !== 'only';
		const bootstrap = isHydrate ? createSSRApp : createApp;

		// keep a reference to the app, props and slots so we can update a running instance later
		let appInstance = appMap.get(element);

		if (!appInstance) {
			appInstance = {
				props,
				slots,
			};
			const app = bootstrap({
				name,
				render() {
					// At this point, appInstance has been set so it's safe to use a non-null assertion
					let content = h(Component, appInstance!.props, appInstance!.slots);
					appInstance!.component = this;
					// related to https://github.com/withastro/astro/issues/6549
					// if the component is async, wrap it in a Suspense component
					if (isAsync(Component.setup)) {
						content = h(Suspense, null, content);
					}
					return content;
				},
			});
			app.config.idPrefix = element.getAttribute('prefix') ?? undefined;
			await setup(app);
			app.mount(element, isHydrate);
			appMap.set(element, appInstance);
			element.addEventListener('astro:unmount', () => app.unmount(), { once: true });
		} else {
			appInstance.props = props;
			appInstance.slots = slots;
			appInstance.component.$forceUpdate();
		}
	};

function isAsync(fn: () => any) {
	const constructor = fn?.constructor;
	return constructor && constructor.name === 'AsyncFunction';
}

Domain

Subdomains

Functions

Dependencies

  • ./static-html.js
  • virtual:astro:vue-app
  • vue

Frequently Asked Questions

What does client.ts do?
client.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in client.ts?
client.ts defines 1 function(s): isAsync.
What does client.ts depend on?
client.ts imports 3 module(s): ./static-html.js, virtual:astro:vue-app, vue.
Where is client.ts in the architecture?
client.ts is located at packages/integrations/vue/src/client.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/integrations/vue/src).

Analyze Your Own Codebase

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

Try Supermodel Free