UNPKG

seia.js

Version:

Lightweight SSR framework for React Server Components

26 lines (25 loc) 985 B
// sort-imports-ignore import './process-polyfill.js'; import './webpack-global.js'; import { hydrateRoot } from 'react-dom/client'; import { createFromReadableStream } from 'react-server-dom-webpack/client.browser'; import { parseAnchorId } from './utils.js'; export const initClientModuleMap = (clientModuleMap)=>{ const lookup = (id)=>{ const { path, anchor } = parseAnchorId(id); return anchor ? clientModuleMap[path][anchor] : clientModuleMap[path]; }; globalThis.__webpack_chunk_load__ = async (id)=>lookup(id); globalThis.__webpack_require__ = (id)=>lookup(id); }; export const run = async ()=>{ const embeddedStream = new Blob([ globalThis.__SEIA_RSC_PAYLOAD ], { type: 'text/plain' }).stream(); const reactRootDom = await createFromReadableStream(embeddedStream); const root = document.getElementById('root'); if (!root) throw new Error('Root element not found'); hydrateRoot(root, reactRootDom); };