@lwc/ssr-runtime
Version:
Runtime complement to @lwc/ssr-compiler
75 lines • 4.8 kB
TypeScript
import { type Stylesheet } from '@lwc/shared';
import { SYMBOL__GENERATE_MARKUP } from './lightning-element';
import type { CompilationMode } from '@lwc/shared';
import type { LightningElement, LightningElementConstructor } from './lightning-element';
import type { Attributes, Properties } from './types';
/** Parameters used by all `generateMarkup` variants that don't get transmogrified. */
type BaseGenerateMarkupParams = readonly [
tagName: string,
props: Properties | null,
attrs: Attributes | null,
parent: LightningElement | null,
scopeToken: string | null,
contextfulParent: LightningElement | null
];
/** Text emitter used by transmogrified formats. */
type Emit = (str: string) => void;
/** Slotted content function used by `asyncYield` mode. */
type SlottedContentGenerator = (instance: LightningElement) => AsyncGenerator<string, void, unknown>;
/** Slotted content function used by `sync` and `async` modes. */
type SlottedContentEmitter = ($$emit: Emit, instance: LightningElement) => void;
/** Slotted content map used by `asyncYield` mode. */
type SlottedContentGeneratorMap = Record<number | string, SlottedContentGenerator[]>;
/** Slotted content map used by `sync` and `async` modes. */
type SlottedContentEmitterMap = Record<number | string, SlottedContentEmitter[]>;
/** `generateMarkup` parameters used by `asyncYield` mode. */
type GenerateMarkupGeneratorParams = readonly [
...BaseGenerateMarkupParams,
shadowSlottedContent: SlottedContentGenerator | null,
lightSlottedContent: SlottedContentGeneratorMap | null,
scopedSlottedContent: SlottedContentGeneratorMap | null
];
/** `generateMarkup` parameters used by `sync` and `async` modes. */
type GenerateMarkupEmitterParams = readonly [
emit: Emit,
...BaseGenerateMarkupParams,
shadowSlottedContent: SlottedContentEmitter | null,
lightSlottedContent: SlottedContentEmitterMap | null,
scopedSlottedContent: SlottedContentEmitterMap | null
];
/** Signature for `asyncYield` compilation mode. */
export type GenerateMarkupAsyncYield = (...args: GenerateMarkupGeneratorParams) => AsyncGenerator<string>;
/** Signature for `async` compilation mode. */
export type GenerateMarkupAsync = (...args: GenerateMarkupEmitterParams) => Promise<void>;
/** Signature for `sync` compilation mode. */
export type GenerateMarkupSync = (...args: GenerateMarkupEmitterParams) => void;
type GenerateMarkupVariants = GenerateMarkupAsyncYield | GenerateMarkupAsync | GenerateMarkupSync;
export declare function renderAttrs(instance: LightningElement, attrs: Attributes, hostScopeToken: string | undefined, scopeToken: string | undefined): Generator<string, void, unknown>;
export declare function renderAttrsNoYield(emit: (segment: string) => void, instance: LightningElement, attrs: Attributes, hostScopeToken: string | undefined, scopeToken: string | undefined): void;
export declare function fallbackTmpl(shadowSlottedContent: SlottedContentGenerator | null, _lightSlottedContent: SlottedContentGeneratorMap | null, _scopedSlottedContent: SlottedContentGeneratorMap | null, Cmp: LightningElementConstructor, instance: LightningElement): AsyncGenerator<string>;
export declare function fallbackTmplNoYield(emit: Emit, shadowSlottedContent: SlottedContentEmitter | null, _lightSlottedContent: SlottedContentEmitterMap | null, _scopedSlottedContent: SlottedContentEmitterMap | null, Cmp: LightningElementConstructor, instance: LightningElement): void;
export declare function addSlottedContent(name: string, fn: unknown, contentMap: Record<string, unknown[]>): void;
interface ComponentWithGenerateMarkup extends LightningElementConstructor {
[SYMBOL__GENERATE_MARKUP]?: GenerateMarkupVariants;
}
export declare class RenderContext {
styleDedupeIsEnabled: boolean;
styleDedupePrefix: string;
stylesheetToId: WeakMap<Stylesheet, string>;
nextId: number;
constructor(styleDedupe: string | boolean);
}
/**
* Create a string representing an LWC component for server-side rendering.
* @param tagName The HTML tag name of the component
* @param Component The `LightningElement` component constructor
* @param props HTML attributes to provide for the root component
* @param styleDedupe Provide a string key or `true` to enable style deduping via the `<lwc-style>`
* helper. The key is used to avoid collisions of global IDs.
* @param mode SSR render mode. Can be 'sync', 'async' or 'asyncYield'. Must match the render mode
* used to compile your component.
* @returns String representation of the component
*/
export declare function serverSideRenderComponent(tagName: string, Component: ComponentWithGenerateMarkup, props?: Properties, styleDedupe?: string | boolean, mode?: CompilationMode): Promise<string>;
export {};
//# sourceMappingURL=render.d.ts.map