import * as nextEntry from 'markstream-react/next' import * as serverEntry from 'markstream-react/server' import React from 'react' import { createMatrixCases, FALLBACK_DEMOS, SERVER_BASIC_NODES, SERVER_CUSTOM_ALT_ID, SERVER_CUSTOM_ALT_NODES, SERVER_CUSTOM_ID, SERVER_CUSTOM_NODES, } from '../src/ssr-lab-data' import { SsrLabPage } from '../src/ssr-lab-page' function readAttr(node: any, name: string) { if (!node?.attrs) return undefined if (Array.isArray(node.attrs)) return node.attrs.find((item: [string, string | null]) => item[0] === name)?.[1] ?? undefined return node.attrs[name] } function renderCustomChildren(props: any) { if (!Array.isArray(props.node?.children) || !props.renderNode || !props.ctx) return null return props.node.children.map((child: any, idx: number) => ( {props.renderNode(child, `${String(props.indexKey ?? 'custom')}-${idx}`, props.ctx)} )) } function ServerParagraphOverride({ node }: any) { return (
{node.raw}
) } function ServerInsightNode(props: any) { return (
{props.node.label}
{renderCustomChildren(props)}
) } function ServerThinkingTag({ node }: any) { return ( ) } function ServerParagraphAlt({ node }: any) { return (
{node.raw}
) } function ServerInsightAlt(props: any) { return (
{props.node.label}
{renderCustomChildren(props)}
) } function ServerThinkingTagAlt({ node }: any) { return ( ) } function renderServerFallbackHtml() { return ( <>
) } function renderServerMatrixHtml() { const items = createMatrixCases(serverEntry, serverEntry) return (
{items.map(item => (

{item.name}

{item.element}
))}
) } function renderServerCustomHtml() { return ( <>
) } interface PagesSsrLabProps { serverBasicHtml: string serverCustomHtml: string serverFallbackHtml: string serverMatrixHtml: string } export default function PagesSsrLabPage({ serverBasicHtml, serverCustomHtml, serverFallbackHtml, serverMatrixHtml, }: PagesSsrLabProps) { return ( ) } export async function getServerSideProps() { const { renderToStaticMarkup } = await import('react-dom/server') serverEntry.setCustomComponents(SERVER_CUSTOM_ID, { paragraph: ServerParagraphOverride, insight: ServerInsightNode, thinking: ServerThinkingTag, }) serverEntry.setCustomComponents(SERVER_CUSTOM_ALT_ID, { paragraph: ServerParagraphAlt, insight: ServerInsightAlt, thinking: ServerThinkingTagAlt, }) return { props: { serverBasicHtml: renderToStaticMarkup( , ), serverCustomHtml: renderToStaticMarkup(renderServerCustomHtml()), serverFallbackHtml: renderToStaticMarkup(renderServerFallbackHtml()), serverMatrixHtml: renderToStaticMarkup(renderServerMatrixHtml()), }, } }