vite-plugin-react-server
Version:
Vite plugin for React Server Components (RSC)
58 lines • 2.32 kB
TypeScript
import type { GenericModuleLoader, PagePropOpt, PropsName } from "../types.js";
type ResolvePropsOptions = {
id: string;
url: string;
exportName: string;
loader: GenericModuleLoader;
};
type ValidPropTypes<T> = T | Promise<T> | Array<T[keyof T]> | Array<[string, T[keyof T]]> | ((url: string) => ValidPropTypes<T>);
type ResolvePropsResult<T extends PagePropOpt, N extends string> = {
type: "success";
key: string;
module?: {
[key in N]: ValidPropTypes<T> | ((url: string) => ValidPropTypes<T>) | (new (url: string) => T);
};
} | {
type: "error";
key: string;
error: Error;
module?: never;
} | {
type: "skip";
key: string;
module?: never;
error?: never;
};
/**
* Resolves props from a module, handling both real and virtual modules.
*
* During development (ssrLoadModule):
* - Real modules have exports available directly on the module object
* - Virtual modules have exports stored in temporaryReferences
*
* During build (createBuildLoader):
* - Transformed modules (with ast/code) have exports as direct properties
* - The exports array contains just the names of those exports
* - We store the module in temporaryReferences for later use
* - We access exports directly from the module object
*
* Props can be:
* 1. A function that takes a URL and returns props
* 2. A direct object of props
* 3. A renamed export (where the actual export name differs from the expected name)
*
* @param options.propsModule - The module object from ssrLoadModule or createBuildLoader
* @param options.path - The normalized path to the module
* @param options.url - The URL route this page handles
* @param options.exportName - The name of the export to resolve (e.g. 'props')
* @param options.temporaryReferences - WeakMap used to store and retrieve virtual module references
*
* @returns A result object containing:
* - type: "success" | "error" | "skip"
* - key: The export name if successful
* - props: The resolved props if successful
* - error: Error message if failed
*/
export declare const resolveProps: <T extends PagePropOpt = PagePropOpt, N extends string = PropsName>({ id, url, exportName, loader, }: ResolvePropsOptions) => Promise<ResolvePropsResult<T, N>>;
export {};
//# sourceMappingURL=resolveProps.d.ts.map