SSR / foldkit-ssr

Lower-level API

SSR.render and SSR.hydrate are built from pieces usable on their own:

  • SSR.envelope(plan, model, { route? }) returns the envelope for a Model, as JSON, and SSR.resume(plan, document, { route? }) reads it back as a Result. SSR.render carries it on the stamped root, beside Foldkit's own stamps; the JSON escapes < as Foldkit escapes its Flags, and U+2028 and U+2029, and the attribute escapes & and " besides, so no string in the Model can break out of the value. Hydration drops the attribute on its first patch, so the browser reads it before it boots.
  • SSR.inspect(plan, model): the plan's coverage as data.
  • Resume.bindings(plan, document, root, model) decodes and checks a page's bindings, and Resume.listen(root, { bindings, onAnswer, events? }) answers events from the markers, one { event, messages, unnamed? } per event. events is the envelope's list of every event the markers name; without it listen reads every element's attributes to find them. SSR.hydrate uses both, passing the list; they are there for a custom boot.
  • Attribute names, for tools and tests: RESUME_ATTRIBUTE (the envelope on the stamped root), STATIC_ATTRIBUTE, BINDING_ATTRIBUTE (a prefix, followed by the event), SLOT_ATTRIBUTE (a placement's root while the server renders) and FALLBACK_FIELD (the posted Message).