UNPKG

@mui/internal-docs-infra

Version:

MUI Infra - internal documentation creation tools.

42 lines 2.25 kB
import * as React from 'react'; import type { Code, CodeHighlighterBaseProps, ContentLoadingProps, VariantExtraFiles, VariantSource } from "./types.mjs"; import type { CompressedFallback } from "./fallbackFormat.mjs"; export interface PrepareInitialSourceOptions<T extends {}> extends CodeHighlighterBaseProps<T> { code: Code; initialVariant: string; initialFilename: string | undefined; initialSource: VariantSource; initialExtraFiles?: VariantExtraFiles; ContentLoading: React.ComponentType<ContentLoadingProps<T>>; /** * Whether to DEFLATE-compress the consolidated residual fallbacks. This only * shrinks the server→client serialized payload, so it pays off only when the * result actually crosses that wire (a server render). On the client there is no * wire — compressing here just to have `CodeHighlighterClient` decompress it right * back is a wasted round-trip — so the isomorphic `CodeHighlighter` entry passes * `typeof window === 'undefined'`. Defaults to `true` for the server-only loaders * (and tests) that always produce wire output; when `false`, the fallbacks stay * inline on `codeForClient`. */ compressResidual?: boolean; } export interface PreparedInitialSource { /** The pre-rendered loading fallback (`<ContentLoading />`). */ fallback: React.ReactNode; /** * The variant/file fallbacks the loading UI won't render, consolidated into a * single DEFLATE blob. Absent when there is nothing worth compressing. */ residualFallbacks?: CompressedFallback; /** The `Code` to send to the client (fallbacks stripped/wired out when compressed). */ codeForClient: Code; } /** * Prepare the loading fallback and the wire `Code` from the initial source. Hoists * the rendered subset onto `ContentLoading` props, strips those fallback HASTs off * `Code`, and consolidates the rest into a compressed `residualFallbacks` blob the * client decodes against the rendered text. The render *decision* (client vs server * load, stream vs await) is the chunk's job; this is just the shared preparation * used by the content path and the server loaders. */ export declare function prepareInitialSource<T extends {}>(props: PrepareInitialSourceOptions<T>): PreparedInitialSource;