Home / Function/ check() — astro Function Reference

check() — astro Function Reference

Architecture documentation for the check() function in server.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  21e9bbd3_b778_f079_1177_b0811fd8fa10["check()"]
  88d29d84_fc17_43e9_f02f_9b64acf73dd5["server.ts"]
  21e9bbd3_b778_f079_1177_b0811fd8fa10 -->|defined in| 88d29d84_fc17_43e9_f02f_9b64acf73dd5
  style 21e9bbd3_b778_f079_1177_b0811fd8fa10 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/integrations/react/src/server.ts lines 13–53

async function check(
	this: RendererContext,
	Component: any,
	props: Record<string, any>,
	children: any,
) {
	// Note: there are packages that do some unholy things to create "components".
	// Checking the $$typeof property catches most of these patterns.
	if (typeof Component === 'object') {
		return Component['$$typeof'].toString().slice('Symbol('.length).startsWith('react');
	}
	if (typeof Component !== 'function') return false;
	if (Component.name === 'QwikComponent') return false;

	// Preact forwarded-ref components can be functions, which React does not support
	if (typeof Component === 'function' && Component['$$typeof'] === Symbol.for('react.forward_ref'))
		return false;

	if (Component.prototype != null && typeof Component.prototype.render === 'function') {
		return React.Component.isPrototypeOf(Component) || React.PureComponent.isPrototypeOf(Component);
	}

	let isReactComponent = false;
	function Tester(...args: Array<any>) {
		try {
			const vnode = Component(...args);
			if (
				vnode &&
				(vnode['$$typeof'] === reactTypeof || vnode['$$typeof'] === reactTransitionalTypeof)
			) {
				isReactComponent = true;
			}
		} catch {}

		return React.createElement('div');
	}

	await renderToStaticMarkup.call(this, Tester, props, children);

	return isReactComponent;
}

Domain

Subdomains

Frequently Asked Questions

What does check() do?
check() is a function in the astro codebase, defined in packages/integrations/react/src/server.ts.
Where is check() defined?
check() is defined in packages/integrations/react/src/server.ts at line 13.

Analyze Your Own Codebase

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

Try Supermodel Free