rwsdk
Version:
Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime
23 lines (22 loc) • 1.26 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Preloads } from "./preloads.js";
import { Stylesheets } from "./stylesheets.js";
// Note: This is a server component, even though it doesn't have the "use server"
// directive. It's intended to be imported and used within the RSC render pass.
export const assembleDocument = ({ requestInfo, pageElement, shouldSSR, }) => {
// todo(justinvdm, 18 Jun 2025): We can build on this later to allow users
// surface context. e.g:
// * we assign `user: requestInfo.clientCtx` here
// * user populates requestInfo.clientCtx on worker side
// * user can import a read only `import { clientCtx } from "rwsdk/client"`
// on client side
const clientContext = {
rw: {
ssr: shouldSSR,
},
};
const Document = requestInfo.rw.Document;
return (_jsxs(Document, { ...requestInfo, children: [_jsx("script", { nonce: requestInfo.rw.nonce, dangerouslySetInnerHTML: {
__html: `globalThis.__RWSDK_CONTEXT = ${JSON.stringify(clientContext)}`,
} }), _jsx(Stylesheets, { requestInfo: requestInfo }), _jsx(Preloads, { requestInfo: requestInfo }), _jsx("div", { id: "hydrate-root", children: pageElement })] }));
};