@lastshotlabs/slingshot-ssr
v0.0.2
Published
SSR, ISR, and page-routing plugin for Slingshot
Readme
title: Human Guide description: Human-maintained guidance for @lastshotlabs/slingshot-ssr
@lastshotlabs/slingshot-ssr is Slingshot's server-rendering package. It owns route resolution,
server action routing, metadata routes, draft-mode routing, page-declaration support, and the
middleware that turns Slingshot context plus a renderer into HTML responses.
When To Use It
Use this package when your app needs:
- file-based server routes rendered on the server
- route loaders that read directly from Slingshot context instead of making HTTP calls back into the app
- metadata routes such as sitemap or robots behavior
- server actions mounted under the Snapshot-compatible action endpoint
- entity-driven page declarations, renderer navigation config, or ISR
- hybrid deployments that mix SSR with pre-rendered static output
Minimum Setup
createSsrPlugin() has three practical requirements:
- a renderer that satisfies the
SlingshotSsrRenderercontract serverRoutesDirassetsManifest
After that, the most common optional config is:
cacheControlexcludedevModestaticDirisrtrustedOriginsserverActionsDirruntimedraftModeSecretpagesnavigation
If you use layouts, your renderer also needs renderChain(). That requirement is architectural, not
optional polish.
What You Get
The plugin wires several surfaces at once:
- draft-mode routes under
/api/draftwhendraftModeSecretis configured - server action routing under
/_snapshot - metadata route registration from the server route tree
- SSR middleware that resolves routes, loads data, and renders HTML
- optional ISR invalidators stored in plugin state under
slingshot-ssr:isr - optional page-declaration support for renderer-owned shell/navigation experiences
- entity-event subscriptions that revalidate ISR tags for referenced pages
This is the package that makes route loaders, shell rendering, metadata, and revalidation behave as one system instead of separate app glue.
Common Customization
Start in these files:
src/plugin.tsfor lifecycle and middleware registrationsrc/config.schema.tsfor supported config and validationsrc/types.tsfor the renderer and loader contractssrc/resolver.tsandsrc/pageResolver.tsfor route and page resolutionsrc/pageLoaders.tsfor loader executionsrc/metadata/andsrc/draft/for metadata and draft-mode behavior
The generated package reference for slingshot-ssr is sourced from entrypoint and type-level JSDoc,
primarily src/index.ts plus the exported contracts in src/types.ts. If you change renderer,
loader, page, metadata, draft-mode, or static-params behavior, update those comments in the same
diff rather than trying to patch generated docs afterward.
The highest-leverage decisions are usually:
- renderer contract shape
- route resolution and exclusion behavior
- ISR cache adapter choice
- server action trust policy
- whether pages are file-based, manifest-backed, or both
Gotchas
- In production mode, startup fails if
assetsManifestcannot be read or parsed. That is expected and should remain fail-closed. serverRoutesDirandserverActionsDirmust be absolute paths. Relative paths are rejected at config validation time so route resolution is reproducible across runtime hosts (Bun / Node / Lambda / Edge). Resolve viapath.resolve(import.meta.dir, ...)orpath.join(process.cwd(), ...)before passing them in.renderChain()is required for layouts. If the renderer only implementsrender(), nested layout routing will not behave correctly.- When
pagesand ISR are both enabled, the plugin subscribes to CRUD events for referenced entities so tag revalidation works. Changing that path affects runtime invalidation semantics. staticDiris a serving optimization for already-generated HTML, not a replacement for the SSR route tree.- The dev watcher is best-effort only. It invalidates and rebuilds the route tree when Bun's watch API is available.
Key Files
src/index.tssrc/plugin.tssrc/config.schema.tssrc/types.tssrc/resolver.tssrc/pageResolver.tssrc/pageLoaders.tssrc/metadata/index.ts
Source-Backed Examples
- Content Platform example - SSR, draft mode, metadata, and ISR-oriented composition in
examples/content-platform/
