[]previous and next page

createServerPortals

Creates the collector a server render writes its portals into.

Creates the collector a server render writes its portals into. Without one, a Portal renders nothing on the server. Create one per request: a render clears it before it starts, and one render may produce at most 256 portals (more throw an SsrError whose code is SSR_PORTAL_LIMIT).

Import#

ts
import { createServerPortals } from "@shadow-js/web/server";

Signature#

ts
function createServerPortals(): ServerPortals

Returns#

A new, empty ServerPortals.

Examples#

ts
import { createComponent, createServerPortals, renderToString } from "@shadow-js/web/server";

function App() {
  return <main>Hello</main>;
}
const portals = createServerPortals();
const app = renderToString(() => createComponent(App, {}), { portals });
const page = `<body><div id="app">${app}</div>${portals.html()}</body>`;