@stencil/react-output-target
Version:
React output target for @stencil/core components.
34 lines (33 loc) • 1.59 kB
TypeScript
import type { EventName, ReactWebComponent } from '@lit/react';
type EventNames = Record<string, EventName | string>;
/**
* these types are defined by a Stencil hydrate app so we have to copy the minimal types here
*/
interface RenderToStringOptions {
fullDocument?: boolean;
serializeShadowRoot?: boolean;
prettyHtml?: boolean;
}
export type RenderToString = (html: string, options: RenderToStringOptions) => Promise<{
html: string | null;
}>;
interface CreateComponentForServerSideRenderingOptions {
tagName: string;
properties: Record<string, string>;
renderToString: RenderToString;
}
/**
* Transform a React component into a Stencil component for server side rendering. This logic is executed
* by a React framework e.g. Next.js in an Node.js environment. The function will:
*
* - serialize the component (including the Light DOM) into a string (see `toSerializeWithChildren`)
* - transform the string with the Stencil component into a Declarative Shadow DOM component
* - parse the declarative shadow DOM component back into a React component
* - return the React component
*
* Note: this code should only be loaded on the server side, as it uses heavy Node.js dependencies,
* e.g. `react-dom/server`, `html-react-parser` as well as the hydrate module, that when loaded on
* the client side would increase the bundle size.
*/
export declare const createComponentForServerSideRendering: <I extends HTMLElement, E extends EventNames = {}>(options: CreateComponentForServerSideRenderingOptions) => ReactWebComponent<I, E>;
export {};