[]previous and next page

@shadow-js/web/server

The 33 exports of @shadow-js/web/server: 23 functions, 9 interfaces and 1 component.

Everything @shadow-js/web/server exports, from the TSDoc of its entry point.

Functions#

  • createComponent: Calls a component on the server, untracked, with its own owner and hydration scope, so the hydration keys it hands out depend only on where it sits in the tree.
  • createServerHead: Creates an empty server head collector.
  • createServerPortals: Creates the collector a server render writes its portals into.
  • derived: The server twin of the client derived, which the compiler emits for const x = <expression reading signals> inside a component.
  • deserialize: Rebuilds the value serialize wrote, with its shared references and cycles.
  • escape: Converts any value a JSX child may hold to escaped HTML: the helper compiled server output calls for every dynamic child, and what the renderers call on the app's result.
  • generateHydrationScript: Returns the inline <script> that records the events a user makes before the app has hydrated, so hydrate() can replay them once its handlers are attached (a click made while the bundle loads is not lost).
  • memo: The server twin of memo: nothing is reactive during a server render, so it computes once, on the first read, and returns the cached value on every later read.
  • mergeProps: Merges props objects into one getter-preserving object.
  • normalizeTags: Normalizes what useHead receives: one description, a list, or nothing.
  • renderToStream: Renders an app as a stream of HTML, for the fastest first byte: the shell first (pending Suspense boundaries show their fallback), then one chunk per boundary as its data arrives, in the order the data settles, and finally, when resources resolved, a <script type="application/json" data-sh="RENDER_ID"> block with their values.
  • renderToString: Renders an app to an HTML string synchronously: the simplest server render, for pages whose data is already at hand.
  • renderToStringAsync: Renders an app to an HTML string once its data has loaded: each pass renders with the resource values found so far, the fetches it starts are awaited, and another pass runs while one of them produced a new value.
  • serialize: Serializes data for embedding in a page, as JSON that is safe inside a <script type="application/json"> element.
  • ssr: Joins the static parts of a server template with its dynamic holes into trusted markup: the function compiled server output calls for each element tree.
  • ssrAttribute: Renders one attribute as markup with a leading space, or "" when the attribute is absent: the helper the compiler's server output calls for a dynamic attribute.
  • ssrClass: Renders a class attribute from a class value: the helper the compiler's server output calls for class, className and classList, with the same clsx rules as the client's className.
  • ssrElement: Renders an element from a props object: what compiled server output calls for an element with a spread (<div {...props} />), and the server half of Dynamic and element.
  • ssrHydrationKey: Draws the next hydration key of the current scope and returns it as a data-hk attribute, such as ' data-hk="0-0"': compiled server output calls it for the root element of each template, and the client's hydrate() claims the element by that key.
  • ssrRaw: Marks a string as trusted markup that escape and ssr insert unchanged.
  • ssrSelectValue: The options of a <select> with the ones its value stands for marked selected.
  • ssrStyle: Renders a style attribute from a style value: the helper the compiler's server output calls for style and style: attributes.
  • ssrTextArea: Renders the content of a <textarea> from its value: the helper compiled server output calls for <textarea value={...}> and defaultValue, since a browser ignores a value attribute on a textarea.

Interfaces#

  • AsyncRenderOptions: Options of renderToStringAsync: the RenderOptions plus the limits of the multi-pass render.
  • AsyncRenderResult: What renderToStringAsync resolves to: the markup and the resource data to embed for hydration.
  • Derived: The server twin of the client Derived: what derived returns.
  • HydrationScriptOptions: Options of generateHydrationScript and HydrationScript.
  • NormalizedTag: A validated tag: lower-case attribute names, the text it carries, and its identity.
  • RenderOptions: Options of renderToString, and the base of AsyncRenderOptions.
  • ServerHead: The head of one server render: what useHead, <Title>, <Meta>, <Link>, <Style> and <Base> registered while the app rendered.
  • ServerPortals: The markup of the portals a server render produced (see createServerPortals).
  • StreamOptions: Options of renderToStream.

components#

  • HydrationScript: generateHydrationScript as a component, for a document rendered with server JSX: <HydrationScript nonce={nonce} /> in the <head>.