@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
77 lines (73 loc) • 3.34 kB
JavaScript
import * as React from 'react';
import { createCoordinatedLazy } from "../CoordinatedLazy/createCoordinatedLazy.mjs";
import { createClientProps } from "./createClientProps.mjs";
import { CodeHighlighterClient } from "./CodeHighlighterClient.mjs";
/**
* The user props the CodeHighlighter chunk threads to its content + loaders. It
* carries the isomorphic CodeHighlighter props plus the values prepared up front:
* the rendered loading `fallback`, the compressed `residualFallbacks`, and the
* resolved `initialVariant`. The content generic is erased here (`{}`); the user's
* real content props ride through `Content`/`contentProps` and are rebuilt by
* `createClientProps`.
*/
/** Props the chunk content/loaders receive (user props + resolved `data`/`loading`). */
import { jsx as _jsx } from "react/jsx-runtime";
/**
* Render the `'use client'` `CodeHighlighterClient` from the resolved chunk props.
* `data` is the `Code` to send to the client; the prepared `fallback`/`residualFallbacks`
* ride through the user props. `CodeHighlighterClient` owns its own fallback->content
* swap (so the chunk is configured `contentManagesSwap`).
*/
function CodeHighlighterChunkContent(props) {
const {
data,
loading,
...userProps
} = props;
const clientProps = createClientProps({
...userProps,
code: data ?? userProps.code
});
return /*#__PURE__*/_jsx(CodeHighlighterClient, {
...clientProps
});
}
/**
* The chunk's loading placeholder, used as the Suspense fallback while a server
* loader streams. It renders the pre-prepared `<ContentLoading />` element threaded
* through the user props (the actual loading UI is built up front by
* `prepareInitialSource`).
*/
function CodeHighlighterChunkLoading(props) {
return /*#__PURE__*/_jsx(React.Fragment, {
children: props.fallback ?? null
});
}
/**
* The isomorphic chunk that drives `CodeHighlighter`. `CodeHighlighter` computes the
* decision inputs (`controlled`/`isInitial`/`forceClient`/`awaitServerLoad`/
* `skipInitialLoad`) and this routes via the generic chunk decision:
*
* - content / content-initial / attempt-initial-client -> render the client directly
* (it self-manages its swap).
* - server-loader -> dynamically import `CodeSourceLoader` (load all variants).
* - server-initial -> dynamically import `CodeInitialSourceLoader` (load the initial,
* then re-enter this chunk to load the full content).
*
* The `Loader`/`InitialLoader` are only imported when the decision routes to them, so
* the heavy load/parse pipeline stays off the path that renders precomputed content.
*/
export const CodeHighlighterChunk = createCoordinatedLazy({
ChunkContent: CodeHighlighterChunkContent,
ChunkLoading: CodeHighlighterChunkLoading,
// `CodeHighlighter` computes the decision per-render (it depends on more than the
// preloaded value) and passes `controlled`/`isInitial` as overrides, so the config
// predicates always defer (returning `false` disables the default
// "preloaded !== undefined" rule, which would otherwise force content mode because
// CodeHighlighter always has a preloaded `Code`).
isLoaded: () => false,
isInitial: () => false,
Loader: () => import("./CodeSourceLoader.mjs"),
InitialLoader: () => import("./CodeInitialSourceLoader.mjs"),
contentManagesSwap: true
});