packages/astro/src/core/render/README.md
core/renderThis directory contains most of Astro's high-level rendering APIs, including renderPage, createRenderContext, etc.
The codebase has a few abstractions for rendering:
RenderContextEach render (page or endpoint) requires a RenderContext that contains:
Request objectroutepathname (without the base)params and propsstyles, links, scriptsThe RenderContext is agnostic to what's being rendered.
Permitted state: RenderContext should only contain per-request information.
EnvironmentEvery app (dev and prod) has one Environment. It contains a subset of the Astro settings, config, and routes information needed for Astro's runtime to work.
In dev, all of settings, config, and routes are available, so the Environment (aka DevelopmentEnvironment) is derived directly from them. In prod, the Environment is derived from the SSRManifest, an intermediate layer that helps keep the build output lean.
Permitted state: Environment should only contain the global state shared across all requests.
SSRManifestAn SSRManifest is created during a build to save information needed to create an Environment during runtime start-up. The values should be serializable (buildManifest) and deserializable (deserializeManifest).
The serialized string is inlined in the server output and can usually be read from the compiled module's manifest export.
SSRResultThe SSRResult is used by the public rendering APIs at src/runtime/server/. At the top level, it is created by renderPage and passed down to the public rendering APIs. It is also often used in non-Astro pages, like .mdx and .md.
The SSRResult object contains a subset of RenderContext, the state used by the compiled output (cookies, createAstro, resolve, etc), and the state used by the rendering APIs (_metadata).
SSROptionsThe SSROptions is a small wrapper used only in dev to create a RenderContext. It is abstracted to share the same shape for renderPage and renderEndpoint (src/core/endpoint/).
NOTE: The development flow has a different API under src/core/render/dev/ that wraps the core API in this directory.
Environment with settings, config, and routes.SSROptions containing the Request and Environment.renderPage with SSROptions.renderPage creates a RenderContext and calls the core-renderPage API.renderPage creates the SSRResult.render API to render the page!SSRManifest.Environment with the SSRManifest.RenderContext from Request and SSRManifest.renderPage with RenderContext and Environment.render API to render the page!