SHADE is young: 0.1.0-next.2 is a pre-release, and 0.1.0 isn't out yet.

SHADE

Sites in other frameworks

SHADE's own website is Astro (site/), but any site can show SHADE's content. A site in Next.js, SvelteKit, Nuxt or Astro connects through a few packages. They live in their own repository, shade-frontend (frontend/ in the SHADE workspace), with the starter sites. They are workspace packages for now, ready to publish to npm under @shadestack from GitHub Actions (Releases). The paths below, packages/… and starters/…, are in that repository.

Working on the kit

The kit has one version line of its own, starting at 0.1.0. @shadestack/client depends on @shadestack/core within ^0.1.0, and the kit's CHANGELOG.md names the SHADE range each release works with (SHADE ^0.1.0 to start). The kit is on npm as a pre-release under the next tag; the Next.js, Nuxt and SvelteKit adapters are too, each at its own version (npm install @shadestack/nuxt@next). Work on the kit itself happens inside the SHADE workspace, which holds its lockfile and is where its CI runs. Issues and pull requests for the kit and the starters go to shade-frontend; those for the API, the admin, core and the module SDK go to shade.

Supported versions

@shadestack/astro and @shadestack/client have the kit's version. The Next.js, Nuxt and SvelteKit adapters keep their own lines: a new major of their framework comes as an adapter release, without a kit release. Each adapter's peer dependencies name the kit versions it supports (one range on @shadestack/client, @shadestack/render and @shadestack/interactions) and the framework versions. Its changelog (packages/<adapter>/CHANGELOG.md) says what each release changed. Install the adapter with kit packages of a version its range holds.

PackageIts versionSHADEFramework
@shadestack/nextits own (0.1.0)^0.1.0Next.js ^15.0.0 || ^16.0.0, React ^19.0.0
@shadestack/nuxtits own (0.1.0)^0.1.0Nuxt and @nuxt/kit ^4.0.0, Vue ^3.5.0
@shadestack/sveltekitits own (0.1.0)^0.1.0SvelteKit ^2.26.0 || ^3.0.0, Svelte ^5.0.0
@shadestack/astrothe kit'sthe same versionAstro ^7.4.0

Every night the adapters' tests and the render bundles' browser tests run against the framework version SHADE is tested with, the newest release of every older major an adapter's range still promises, and the newest version of the next major once there is one (Releases). A major joins an adapter's range in an adapter release once they pass. Today the tested versions are Next.js 16.4, Nuxt 4.6 and Svelte 5.57; Next.js 17, Nuxt 5 and Svelte 6 have no version to test yet (7 November 2026). Next.js 15 stays in the range without a nightly run.

Starters

The shade-frontend repository has a starter site per framework in starters/: astro, next, nuxt and sveltekit. Copy one to begin a site (Shade Desk's New site does). Each is a minimal site with:

  • pages written by hand on the read client: the home page from the site's settings, and a collection's published entries at /collections/<slug>;
  • the website module's pages (a catch-all route), the editor's Preview (/preview) and the visual editor's canvas (/preview/canvas and its render route), in files its README lists, to delete when the site doesn't use the website module;
  • a .env.example with SHADE_API_URL and SHADE_API_TOKEN.

Every page renders on the server per request, so a publish shows at once and a build needs no SHADE; each README says how to prerender instead. In shade-frontend the starters use the packages by workspace:*, and pnpm test:starters typechecks and builds each. A copy elsewhere depends on the published packages, or links them from a shade-frontend checkout.

Use-case starters

Beside the minimal starters, SHADE has starters for real kinds of sites and tools. Each is written once, in Astro, without the website module, and pnpm test:starters runs its tests and builds it. They use the read client's and the framework packages' shared parts, so the same site in Next, Nuxt or SvelteKit uses the same calls in its own routes.

  • content-site: a blog or news site in the site's languages. Its articles are one public collection (articles, from the client's own module; its README has the definition), and every page is under its language (/nl/…, /en/…). It shows lists (client.collection('articles').list({ locale, page, perPage: 10, sort: '-date' })), an article by slug with links to its other languages (collection.get(slug, locale)), rich text through richTextNodes(body, …) from @shadestack/render (written with the framework's node renderer, never as HTML), search (client.search(q, { locale, collections: ['articles'] }), each highlight's text escaped), a sitemap with hreflang alternates (sitemapXml(entries)), the consent banner, and drafts at /preview (readContentPreview, below). Reads are kept for five minutes and cleared by the rebuild route (/shade-rebuild) that Settings → Other frontends calls.
  • lead-site: a landing page with a contact form, without the website module. The form is one of the forms module's, read on the server as published (GET /api/v1/account/forms/published/<key>?language=<code>; set the key in LEAD_FORM_KEY). The browser solves the forms module's proof-of-work challenge with solveChallenge (@shadestack/client/challenge), then sends the form with callAccountRoute to POST /api/v1/account/forms/submit, so SHADE's spam check and its limit per address count the visitor. A sent form lands in the forms inbox in the admin.
  • internal-tool: a small app for the team, on Astro with the Node server: a stock view that lists a collection's items (stock: a title and a whole-number quantity, without drafts, declared by the client's own module) and lets the team set a new count per row. It uses no SHADE package. It calls the data API (/api/v1/data/collections/<slug>, plain JSON) on the server only, with a data token (kind data, write on the collection):
    • 50 items to a page: GET /api/v1/data/collections/stock;
    • a save per row sends baseVersionId and baseUpdatedAt from the item as the page read it; when someone saved in between, SHADE answers 409 and the page says so;
    • the tool is behind a password (TOOL_PASSWORD, HTTP Basic, any account name). Without one it answers nobody, except under astro dev. Serve it over HTTPS;
    • the token holds what both it and its member's role allow, so a member whose role limits the stock to "Only their own" makes a token that changes only their own items.
  • shop: a site that sells things, on the commerce module's client package (Shop) and SHADE's accounts. It reads the products collection and shade.data('commerce.products') on the server, and uses getProduct(slug) for variants. createCart() keeps its id under shade.kept.cart (as the editor's starter components do, so both share one cart); checkout sends one idempotency key per attempt. /order (set the commerce module's Order page to order) follows an order with createOrderStatus(), and the account page signs in with /api/v1/account/sign-in and lists orders with createMyOrders().
  • bookings: a site that takes appointments, at / (/book in the combined starter), on the appointments module's client package (Appointments) and SHADE's accounts. It reads nothing from SHADE on the server. createBooking({ live: true }) shows free times a fortnight at a time, removes a time someone else takes (with the module's optional realtime capability on), sends SHADE's spam fields and the consent text, and offers the waitlist for a full time. The account page uses createMyAppointments() (with cancelling) and createReminderChoice().
  • shop-and-booking: the two on one site, with one account page for orders, appointments and the reminders choice.

In shop, bookings and shop-and-booking, every status message is said in a live region, and a refused field is marked and gets the focus. Their browser tests run against SHADE's test instance in the SHADE workspace (pnpm test:e2e:starters in shade-frontend, or pnpm test:e2e:starters shop for one).

The shop and bookings in other frameworks

The client packages have no framework of their own. Every store has subscribe (which tells a new listener the state at once) and getSnapshot, so each framework reads it in a few lines. Make the stores per component, never at a module's top level, where a server would share one visitor's cart with the next. They call /api/v1/account/* on the site's own origin, which the framework's development proxy sends to SHADE (Accounts); baseUrl is for SHADE on another address.

A cart in Next.js, as a client component:

'use client'
import { useEffect, useState, useSyncExternalStore } from 'react'
import { createCart } from '@shadestack/commerce-client'

export function Cart() {
  const [cart] = useState(() => createCart({ locale: 'en' }))
  const { data } = useSyncExternalStore(cart.store.subscribe, cart.store.getSnapshot, cart.store.getServerSnapshot)
  useEffect(() => {
    cart.load().catch(() => {})
    return cart.stop
  }, [cart])
  if (!data.view) return <p role="status">Loading…</p>
  return (
    <ul>
      {data.view.lines.map(line => (
        <li key={line.sku}>
          {line.title}: {line.amount}
          <button type="button" onClick={() => cart.remove(line.sku)}>Remove {line.title}</button>
        </li>
      ))}
    </ul>
  )
}

Vue stores need a shallowRef (onScopeDispose(booking.store.subscribe(next => { state.value = next }))); a Svelte store is the store as it is ($state on orders.store).

On a server the stores stay idle and open nothing, so these render empty on the server and fill in the browser.

This page covers the packages a site imports. The website editor's packages, which those build on, have pages of their own: accounts: sign-in and modules' routes, @shadestack/tree, expressions and styles, @shadestack/render with the editor's canvas, @shadestack/interactions and @shadestack/a11y.

What a site needs from SHADE:

  • a read token (API tokens), and the API's address;
  • the content: client.site(), client.collection(slug) and the rest of the API, and with the website module client.page(slug, locale) (the site client, createSiteClient);
  • with the website module, its theme: themeToCss(site.theme) (or the module's GET /api/v1/content/website/theme.css), so the theme's CSS variables exist. An instance without the module gives no theme, and the site styles itself. The site's styles (the module's styles.css) refer to the theme's variables but leave them out, so they are written once, from the current theme;
  • its address listed under Settings → Other frontends when its visitors use forms, page views or accounts.

@shadestack/client

Framework-free; the framework packages build on it. Its root entry is core's read client and needs none of the website editor's packages. A site whose pages the website module keeps also installs @shadestack/render, @shadestack/tree and @shadestack/interactions (the client's optional peer dependencies) for @shadestack/client/render and @shadestack/client/canvas.

Each framework package gives its own API (the next sections), plus createShadeClient, ShadeApiError and the types of what the read client answers. The rest of the client's names (createSiteClient, themeToCss, slugOfSegments and the others below) come from @shadestack/client and @shadestack/client/render, never from a framework package.

import { createSiteClient, themeToCss } from '@shadestack/client/render'

const shade = createSiteClient({ baseUrl: 'https://admin.example.com', token: process.env.SHADE_API_TOKEN! })
const [site, page] = await Promise.all([shade.site(), shade.page('about')])

The website module's pages are built from elements: their content is page.tree. Render it with resolvePage (@shadestack/render) and the package's ShadeTree. @shadestack/client/render does the server side, the same for every framework:

  • renderPublishedPage(page, { client }) fetches the site and the data sources' items and resolves the page ({ site, result }).
  • renderPublishedPart(part, layout, { client }) does a header or footer under its own tree id (defaultLayout(client, locale) for a site's own pages).
  • renderInputFor(page, { site, sources }) is the input alone, for a site that fetched the data itself. It takes the page's media, localStyles (so nodes with local styles get their data-s key), entry, site ({ name, url }) and the items of the data sources the page's Each nodes loop over (pageSources, then shade.data(source, parameters, locale, page) with pageAddress(page)).
  • Options: tree (the editor's unsaved one), edit, deferIslands and strict (on by default: a data source that could not be read fails the render; off, it renders empty with an issue data; a source that is gone, 404, renders empty either way).
  • Also: mergeInteractions, nodesWithInteractions, pageLanguages, pageComponents, mediaFile and visitorProjection.

SHADE's own site renders with it (site/src/lib/page.ts, src/pages/[...slug].astro). The library components a page uses come with it (page.components): give them to resolvePage as components, each with treeId: component-<name>, and their localStyles under those tree ids. On the canvas, page.component previews a component alone.

A prerendered page defers its server islands (serverIslands: 'defer'; in Astro ShadeTree with accountApi; in Next, Nuxt and SvelteKit deferServerIslands and the island route: deferred server islands), so they render per request for whoever is signed in. Their bindings read visitor.signedIn ({ signedIn: false } for nobody) and the projection's name and email. visitorProjection sends SHADE only the visitor's shade_account.* cookies, never the site's others, and renders the island as signed out when SHADE doesn't answer within 3 seconds.

The site's compiled styles are at /api/v1/content/website/styles.css. SHADE's own site writes them, after the theme's web fonts and variables, into its build as one cached file (/styles/<hash>.css) and keeps them in the page only on the preview and edit routes. On the edit route, connectCanvas puts the editor's unsaved styles (the canvas protocol's styles) in a constructed style sheet (document.adoptedStyleSheets) in place of the page's <style data-shade-styles>, which it removes. In edit mode every element carries its data-s key.

Entry points:

  • createShadeClient (the root entry): core's typed read client (/api/v1/content): the site data, media, data sources, collections, and any module's read model by its path (read<T>(path, query)). It knows no module. shade-types, the package's command, writes the instance's collection types for it (Collections).
  • createSiteClient (@shadestack/client/render): core's client with the site's pages, redirects, layout, preview and canvas from the website module's read models, and the site data with its theme (SiteData); pagesPlugin names another module that gives a site its pages. The pages' shapes (PublishedPage, PublishedPart, PublishedLayout, PublishedTheme) are @shadestack/render's. It and every package's shadeFromEnv take the types shade-types writes as well (shadeFromEnv<ShadeCollections>()).
  • Also in @shadestack/client/render: themeToCss, fontFacesCss (@shadestack/styles' own), findPage, shadeFromEnv (a site client), slugOfSegments, and hasMainHeading(tree) (whether a page has its own h1 anywhere it shows nodes; without one, give it its title as a visually hidden h1). The root entry has the content types. resolveImage (an image field's value against a page's media) is in @shadestack/core/schema.
  • @shadestack/client/canvas: connectCanvas, the site side of the website editor's canvas.
  • @shadestack/client/preview: what every framework's preview route builds on (below): readPreview(client, token), previewHeaders(), previewPolicyFromEnv(env, { scripts, styles }) and isPreviewPath.
  • @shadestack/client/rebuild: readRebuildRequest(request, token), what every framework's rebuild route builds on.
  • @shadestack/client/content-security: the site's policy (policyDirectives, policyText) and the hashes of what a page wrote itself (scriptHashes, styleHashes, headOf), on the server only; @shadestack/astro builds its policy on it too.
  • callAccountRoute(plugin, path, options): a module's route on the account API, with the account's cookie for its account routes; see Accounts: sign-in and modules' routes.
  • reportErrors({ accountUrl, enabled?, maxPerPage?, release? }): the site's browser errors to SHADE's error log, where they show on the Errors screen as Site. Off until the site calls it, in the browser, once:
    import { reportErrors } from '@shadestack/client'
    reportErrors({ accountUrl: 'https://admin.example.com', enabled: import.meta.env.PROD })
    

    It sends uncaught errors and unhandled promise rejections to POST /api/v1/account/errors: the name, message and stack, the page's path without its query string or hash, and release when given (the site build the page came from: letters, digits and ._@+-, at most 100), so a forwarded error points at the build that caused it. It sends no cookies (credentials: 'omit'), and uses a text/plain body with keepalive, so there is no preflight and a report still leaves while the page unloads. Each different error is sent once, at most maxPerPage (5) per page load; the call returns a function that stops. SHADE takes reports from the Site URL's origin only (other frontends are refused), at most 16 KB each and 30 per visitor address per ten minutes. Framework packages leave it to the site: call it from the site's own client-side script.

Preview and rebuild

Every framework package gives a site the two routes SHADE calls, with the contract SHADE's own Astro site keeps.

The preview route. The website module's Preview links to <Preview address>/preview?token=… (a signed token of ten minutes), and the admin shows it in a frame. The route reads the draft with the token (readPreview(client, token): SHADE checks the token) and renders it like any page:

  • Without a token it answers 400 (Missing preview token). For a token SHADE refuses, or a page that is gone, it shows the expiry message (This preview link has expired. Open the preview again from the editor.). Any other failure is an error, never an expired link.
  • It is never cached, indexed or sent on as a referrer (previewHeaders(): Cache-Control: no-store, X-Robots-Tag: noindex, nofollow, Referrer-Policy: no-referrer), on the page and on any data the framework fetches for it.
  • Outside development it has the site's Content-Security-Policy (previewPolicyFromEnv): the site's files, SHADE's account API (SHADE_ACCOUNT_URL, else SHADE_API_URL) and media (SHADE_MEDIA_BASE_URL, else <SHADE_API_URL>/uploads), no unsafe-inline, and frame-ancestors with only the admin (SHADE_API_URL's origin). The page's own inline scripts and styles are allowed the way its framework marks them (Next's nonce, the parts of the page Nuxt writes itself, SvelteKit's nonce and the head's hashes); a script or style in the rendered body never applies.

The rebuild route. After a publish SHADE calls a build hook: a POST with no body to the address in the website module's Build hook URL or a frontend's (Settings → Other frontends), the secret in the address, within 10 seconds, never following a redirect. The route takes only the site's SHADE_REBUILD_TOKEN (?token=… or Authorization: Bearer …, compared in constant time, 401 otherwise and always while it is not set; never logged, never in the browser) and then does what its framework does for new content. A build hook says nothing of what changed, so the whole site is renewed. Set the hook to https://<site>/shade-rebuild?token=<SHADE_REBUILD_TOKEN>. The admin shows the build as Sent to the builder: these routes send no build report (only SHADE's own site runner does).

Previews of entries and releases (a release is the editorial module's). A site without the website module shows drafts too: list it under Settings → Other frontends with its Preview address (/preview), and the admin's Preview button and share links of entries and releases go to <site>/preview?token=…. The route reads what the link shows with readContentPreview(client, token) from @shadestack/client/preview (client.contentPreview(token): an entry's version or a release, in the published shapes). It has the same contract as the page preview above: 400 without a token, the expiry message for a link SHADE refuses (expired, revoked, or its maker may no longer read it), and previewHeaders() on the answer.

A release that holds the website module's theme is shown in that theme: previewTheme(preview) gives the theme version's tokens and web font faces, or nothing when the preview has no theme (then the published theme stands). Write them with themeToCss and fontFacesCss, as SHADE's own site does.

The token is in the address: keep the page out of caches and search engines, send no referrer (the headers do; add <meta name="robots" content="noindex"> and <meta name="referrer" content="no-referrer"> too) and never log the address. The content-site starter does all of it (starters/content-site/src/pages/preview.astro).

A page rendered per request already reads SHADE every time; the rebuild route is for what the framework keeps (Next.js's cache, Nuxt's cached routes). A prerendered or exported site, in any framework, needs a new build instead: point the build hook at the host's deploy hook (Vercel, Netlify and Cloudflare each give one).

@shadestack/astro

SHADE's own site uses it; so can any Astro site.

// astro.config.mjs
import { shade } from '@shadestack/astro/integration'
export default defineConfig({ integrations: [shade()] })
  • shade(options) declares SHADE_API_URL, SHADE_API_TOKEN and SHADE_ACCOUNT_URL (read with astro:env/server) and lets Vite compile SHADE's packages. Each of these parts can be switched off with false:
    • plugins: fetches the site parts (their head) of the server packages installed on SHADE before the build. The site imports them from virtual:shade/module-sites and needs @shadestack/module-sdk and zod as dependencies, see Modules. devModules (module folders) adds their site parts in astro dev.
    • media: copies the pages' images into the build.
    • search: indexes the pages for the site's search with Pagefind.
    • contentSecurity: puts a Content-Security-Policy in every page, by hash, with no unsafe-inline. It covers only what the page wrote itself, never what its content holds: the inline scripts and <style> blocks in the <head>, Astro's own server island scripts in the body (held to the exact shape Astro writes), and an Image's focal point with unsafe-hashes, only on a page that has one. The scripts Astro bundles from components are written as files, never into the page. A script, <style> or style attribute anywhere else in the body is blocked, so a frontend's own inline code goes in the <head> or in a file.
  • staticHost (default SHADE_STATIC_HOST; off, a build for Caddy, when neither is set): 'cloudflare' (Workers with static assets), 'netlify', or for Netlify { host, accountApiUrl, siteServerUrl } (default ACCOUNT_API_URL and SITE_SERVER_URL). It runs last in the build and writes into the uploaded folder _headers (the Caddyfile's security and cache headers, and the media library's SVG policy on /media/*.svg), _redirects (the site's redirects in the host's format; on Netlify also a not-found rule per language) and <language>/404.html beside each <language>/404/index.html; it removes redirects*.caddy. It is opt-in, because a build served by Caddy must not carry a worker or files Caddy would serve. See Hosting the site on a static host.
    • Cloudflare: the Worker is @shadestack/cloudflare's, set up in the site's wrangler.jsonc, not in the build; the build warns without SHADE_ISLAND_SECRET.
    • Netlify: the forwarding is an Edge Function written outside the uploaded folder, .netlify/v1/edge-functions/shade-forward.js, declared inline for /api/v1/account/* and /_server-islands/*.
    • Both forward with one fetch handler, @shadestack/client/forward. Each reads SHADE_PROXY_SECRET from the host's runtime environment (the Worker's env, Netlify.env) and takes the visitor's address from the host (CF-Connecting-IP, context.ip), never from a header the visitor sent. It reads the pages and redirects from SHADE (the website module's /pages and /redirects).
  • @shadestack/astro/redirects: the redirects in each format, with one filter for all (not a page's path, not the home page, not the paths the site's server answers itself: /api/, /_server-islands/, /shade-island, /_astro/ and /preview): caddyRedirects (the site's redirects.caddy page), cloudflareRedirects and netlifyRedirects. An old path with * is a pattern to each server, so it gets no rule (its meta-refresh page still works).
  • @shadestack/astro itself has no root entry; import the client's names from @shadestack/client.
  • @shadestack/astro/site: the consent banner (ConsentBanner, restyled by the site's --consent-* variables), its footer link (ConsentSettingsLink), ConsentGate for a module's head part that waits for consent (see The consent banner) and Image. The skip link in your frame says site.words.skipLink (see The site's words). The header and footer are trees the website module gives with each page (PublishedPage.header, .footer), rendered with ShadeTree like the page.
  • @shadestack/astro/content-security: previewPolicy for a preview route's middleware: the site's policy (styles by hash too, no unsafe-inline) with frame-ancestors for the admin. Give it to the route with and without a trailing slash (/preview/ renders the same page).
  • @shadestack/astro/tree: ShadeTree and ShadeHead for the new editor's pages (@shadestack/render), and applyCacheHeaders(Astro, result). Call the latter in the page's frontmatter, where resolvePage runs, so a page that is the visitor's own is sent with Cache-Control: private, no-store. Only the frontmatter is sure to run before Astro sends the headers: ShadeTree sets the header too, but only as a fallback, which is lost under streaming when it stands in a layout or component that awaits something first.
---
// src/pages/[...slug].astro
import { resolvePage } from '@shadestack/render'
import { applyCacheHeaders, ShadeTree } from '@shadestack/astro/tree'
import Layout from '../layouts/Layout.astro'

const result = resolvePage(input) // the page's tree, components, data and language
applyCacheHeaders(Astro, result)
---
<Layout><ShadeTree result={result} /></Layout>

Server islands on a static host. With SHADE_ISLAND_SECRET in the build's environment, a page's per-visitor parts are sealed (deferServerIslands of @shadestack/client/islands, as Next, Nuxt and SvelteKit do) instead of Astro's server:defer. ShadeTree writes their placeholders, and a page that has some loads @shadestack/render/server-islands in its own chunk, which fills them from the island route. It asks the address in the head's <meta name="shade-island-url"> (SHADE_ISLAND_URL, the site's Node server on the instance, asked with credentials: 'include'), else the page's own origin. The route is serverIslandRoute(env, { siteOrigin }): with siteOrigin it also answers that origin from another address of the same site (Sec-Fetch-Site: same-site and exactly that Origin), with CORS and credentials. SHADE's site seals in src/lib/page.ts and serves the route in src/pages/shade-island.ts, with Astro's site as siteOrigin.

The Cloudflare Worker (@shadestack/cloudflare) renders nothing personal: /api/v1/account/* is forwarded to ACCOUNT_API_URL when it is set (404 otherwise), and everything else is the assets binding. Its answers get the site's security headers, which _headers doesn't reach. The template (template/wrangler.jsonc, template/worker.ts) runs it first for that path only (run_worker_first). proxySecret is read from the Worker's env per request and goes to the account API only, with CF-Connecting-IP as X-Shade-Client-Ip; both headers are dropped when a visitor sends them.

Starter: starters/astro (a Node server, output: 'server').

The site's words

The few words SHADE's own parts on a site say themselves come with the site data, in its language: site.words. They are SHADE's language files' site texts, so a language is one more file in SHADE. The packages show what they're given; none of them chooses a language.

WordWhere it shows
skipLinkyour frame's skip link, and the shade:skip-link widget without a label
close, navigation, menu, colourMode, light, dark, pauseMotionthe widgets' own words, where the editor gave none
consent.*the consent banner and its footer link
embed.*an embed's notice

Each word is the page's language's, else its primary language's (de for de-AT), the site's default language's or English's, word by word. renderInputFor gives the rendering core the words; a page rendered without them leaves out the widgets that would need a word, with an issue that says so.

One banner for every framework: @shadestack/client/consent writes its markup and runs it in the browser, and each package gives a thin wrapper held to the same conformance fixture. Render it while site.consent has categories (it renders nothing otherwise), never on the preview page, and put the settings link in the footer: a page without the link shows a floating Privacy settings button once the visitor chose.

FrameworkBanner and footer linkStylesheet
AstroConsentBanner, ConsentSettingsLink from @shadestack/astro/siteincluded
NextConsentBanner, ConsentSettingsLink from @shadestack/nextimport '@shadestack/client/consent.css' in the root layout
NuxtShadeConsentBanner, ShadeConsentSettingsLink (the module registers them; props in kebab case, :account-api-url)added by the module
SvelteKitConsentBanner, ConsentSettingsLink from @shadestack/sveltekitimport '@shadestack/client/consent.css' in the root layout

The banner takes categories={site.consent}, words={site.words.consent}, configuration={site.consentConfiguration} and accountApiUrl; the link takes words. For example in Astro:

<ConsentBanner categories={site.consent} words={site.words.consent} configuration={site.consentConfiguration} accountApiUrl={accountApiUrl} />
<ConsentSettingsLink words={site.words.consent} />

Fetch the site data in the page's language so the words match (see The site's words).

  • The three buttons look the same; each category shows why it is asked, where it loads from, its cookies and how long they live, and the outside party's privacy statement.
  • The choice is kept in the visitor's browser per category and version: a new or changed category asks again.
  • configuration (the site data's consentConfiguration) and accountApiUrl (the account API's address, ACCOUNT_API_URL) let the banner send a receipt where a category needs proof, to <accountApiUrl>/api/v1/account/consent-receipt with the visitor's session, and show its reference in the settings. Without them no receipt is sent.
  • Taking a category back expires its declared first-party cookies and reloads the page.
  • Modules' scripts ask window.shadeConsent.has('<plugin>.<key>') and hear shade:consent on document.
  • An outside video or map waits behind a notice until the visitor allows its category. The website editor's shade:embed widget does this on its own; a page written by hand uses consentEmbedHtml({ category, url, title, ratio }, site.consent, site.words.embed) from @shadestack/client/consent (empty when the address is not one of the category's hosts). Load this one makes that frame only; Always allow keeps the category in the visitor's choice (window.shadeConsent.grant(key)). The frame is lazy, named by the title, sandboxed and from a host the category names; the site's frame-src comes from the module's site sources.
  • A module's head part that waits for consent (Astro): a module with categories names the category that gates its head part (consent.head, published as the category's head: true). Render that head part inside <ConsentGate category={key}>: an inert <template> the banner clones into the head once the visitor allows it. Its inline scripts are hashed with the rest of the head, so they run under the page's policy.

@shadestack/next

React, for Next.js (App Router).

// app/[[...slug]]/page.tsx
import { findPage, resolvePage, shadeFromEnv, ShadeTree } from '@shadestack/next'
import { notFound } from 'next/navigation'

export default async function Page({ params }: { params: Promise<{ slug?: string[] }> }) {
  const shade = shadeFromEnv()
  const [site, page] = await Promise.all([shade.site(), findPage(shade, (await params).slug)])
  if (!page) notFound()
  const result = resolvePage(input) // the page's tree, components, data and language, as above
  return <main><ShadeTree result={result} interactions={page.interactions} /></main>
}
  • shadeFromEnv() (SHADE_API_URL, SHADE_API_TOKEN) and findPage(client, segments) (null for a page that does not exist, and for a malformed segment such as a lone %: answer 404, never 500). All three framework packages take them from @shadestack/client/render and only adapt their route parameters.
  • With the website module, put themeToCss(site.theme) in a <style> of the root layout, and link @shadestack/render/render.css once.
  • ShadeTree and shadeMetadata for the new editor's pages (@shadestack/render), ShadeJsonLd for their structured data, and await shadeNoStore(result) in a page that is the visitor's own (ShadeTree warns once on the server when it renders such a result that shadeNoStore never saw). With interactions, ShadeTree starts the page's interactions in the browser once it is mounted, and again with the next page's.
  • A statically built page's server islands (deferred): resolve with serverIslands: 'defer', render await deferServerIslands(result), and add the island route:
    // app/shade-island/route.ts
    import { serverIslandRoute } from '@shadestack/next'
    
    export const GET = serverIslandRoute()
    

    Set SHADE_ISLAND_SECRET at build time and on the server. A site with a basePath in next.config passes it to ShadeTree (basePath="/docs"), so the islands are asked for at /docs/shade-island; Next has no public way for a package to read it. A fully static export (output: 'export') has no server for the route: its islands stay empty.
  • The preview route (preview and rebuild): shadePreviewProxy in the site's proxy answers 400 without a token and gives the request a fresh nonce in its Content-Security-Policy, which Next puts on its own scripts. The page reads the draft with readPreview, and its layout puts the nonce (shadePreviewNonce()) on its own <style> blocks. Next has no way for a page to answer 401, so an expired link is notFound() (404) with the route's own not-found.tsx. Give the preview a root layout of its own (a route group per root layout), so reading the nonce doesn't make the site's other pages dynamic.
    // proxy.ts (middleware.ts before Next.js 16)
    import { shadePreviewProxy } from '@shadestack/next'
    
    export const proxy = (request: Request) => shadePreviewProxy(request)
    export const config = { matcher: ['/preview'] }
    
    // app/(preview)/preview/page.tsx
    import { readPreview, ShadeTree, shadeFromEnv } from '@shadestack/next'
    import { renderPublishedPage } from '@shadestack/client/render'
    import { notFound } from 'next/navigation'
    
    export const metadata = { robots: { index: false, follow: false } }
    
    export default async function Preview({ searchParams }: { searchParams: Promise<{ token?: string }> }) {
      const shade = shadeFromEnv()
      const preview = await readPreview(shade, (await searchParams).token)
      if (!('page' in preview)) notFound()
      const { result } = await renderPublishedPage(preview.page, { client: shade })
      return <main><ShadeTree result={result} interactions={preview.page.interactions} /></main>
    }
    

    An expired link is notFound(): give the route a not-found.tsx that says This preview link has expired. Open the preview again from the editor. In app/(preview)/layout.tsx, write the theme as <style nonce={await shadePreviewNonce()}>.
  • The rebuild route: revalidateRoute() takes SHADE_REBUILD_TOKEN and revalidates every page (revalidatePath('/', 'layout')), so the next visit renders each with the content SHADE gives now.
    // app/shade-rebuild/route.ts
    import { revalidateRoute } from '@shadestack/next'
    
    export const POST = revalidateRoute()
    

    A static export (output: 'export') has nothing to revalidate: point the build hook at the host's deploy hook.

Starter: starters/next. Its canvas render route writes the rendering core's HTML (toHtml from @shadestack/render): Next keeps react-dom/server out of route handlers.

@shadestack/sveltekit

Svelte 5, for SvelteKit.

// src/routes/[...slug]/+page.server.ts
import { env } from '$env/dynamic/private'
import { error } from '@sveltejs/kit'
import { findPage, shadeFromEnv } from '@shadestack/sveltekit'

export async function load({ params }) {
  const shade = shadeFromEnv(env)
  const [site, page] = await Promise.all([shade.site(), findPage(shade, params.slug)])
  if (!page) error(404)
  return { site, page }
}
<!-- src/routes/[...slug]/+page.svelte -->
<script>
  import { ShadeTree } from '@shadestack/sveltekit'
  let { data } = $props()
</script>

<main><ShadeTree result={data.result} interactions={data.page.interactions} /></main>

with result from resolvePage in the load function. Import the theme's CSS (themeToCss(site.theme), with the website module) and @shadestack/render/render.css in the root layout.

  • shadeFromEnv(env) takes $env/dynamic/private; findPage(client, params.slug) returns null for a page that does not exist. SvelteKit 3 declares a site's variables in src/env.ts (defineEnvVars) and gives them as $app/env/private: pass import * as env from '$app/env/private' where these examples pass $env/dynamic/private's env, as the starter does. SvelteKit 3 also renamed $app/environment to $app/env and $lib to #lib.
  • ShadeTree and ShadeHead for the new editor's pages (@shadestack/render). In the load function, shadeNoStore(result, setHeaders) is for a page that is the visitor's own: it sends the page and its __data.json with Cache-Control: private, no-store (ShadeTree warns once on the server when it renders such a result that shadeNoStore never saw). With interactions, ShadeTree starts the page's interactions in the browser once it is mounted, and again with the next page's: SvelteKit keeps the page's component between pages of the same route.
  • A prerendered page's server islands (deferred): in its load, resolve with serverIslands: 'defer' and return await deferServerIslands(result, env) (import * as env from '$env/static/private', since a prerendered load can't read the dynamic environment), and add the island route:
    // src/routes/shade-island/+server.ts
    import { env } from '$env/dynamic/private'
    import { serverIslandRoute } from '@shadestack/sveltekit'
    
    export const prerender = false
    export const GET = serverIslandRoute(env)
    

    Set SHADE_ISLAND_SECRET at build time and on the server. ShadeTree asks for the route under the app's base path (paths.base, from $app/paths).
  • The preview route (preview and rebuild): its load reads the draft with readPreview and answers SvelteKit's error(status, message) for a missing or expired token. shadePreviewHandle(env, dev) (@shadestack/sveltekit/preview, server only) in src/hooks.server.ts sends the route and its __data.json with the preview's headers, and the page with its policy. SvelteKit marks its own start script only when the site sets kit.csp, so the preview needs it: the handle takes SvelteKit's nonce (or hash) from SvelteKit's policy and the <head>'s hashes, and refuses to answer the preview without SvelteKit's (an error naming kit.csp). How to set it: SvelteKit's content security policy.
    // src/hooks.server.ts
    import { dev } from '$app/environment'
    import { env } from '$env/dynamic/private'
    import { shadePreviewHandle } from '@shadestack/sveltekit/preview'
    
    export const handle = shadePreviewHandle(env, dev)
    

    The route's load is the same as the Next page: readPreview(shade, url.searchParams.get('token')), error(preview.status, preview.message) unless 'page' in preview, then renderPublishedPage and return { page: preview.page, result }, with export const prerender = false.
  • Rebuilding: SvelteKit has no revalidation of its own. Its prerendered pages are files, so SHADE's build hook goes to the host's deploy hook, which builds the site again; pages rendered per request read SHADE every time and need nothing. (Vercel's ISR, for a site that uses it, is Vercel's own on-demand revalidation, outside SvelteKit.)

Starter: starters/sveltekit (SvelteKit 3, @sveltejs/adapter-node). Its src/hooks.server.ts allows the scripts of the page's <head> (the theme's colour mode script) by their hash in SvelteKit's policy on every page, as shadePreviewHandle does for the preview.

SvelteKit content security policy

The preview needs kit.csp: SvelteKit puts a nonce or hash on the scripts it writes only when the site sets it, and the preview's policy allows no other inline script. kit.csp holds for every page of the site, not only the preview. SvelteKit 3 takes its options in vite.config (sveltekit({ csp })); SvelteKit 2 in svelte.config.js (kit: { csp }).

// vite.config.js (SvelteKit 3)
export default defineConfig({
  plugins: [sveltekit({
    csp: { mode: 'auto', directives: { 'script-src': ['self'] } }
  })]
})

With mode: 'auto', pages rendered per request get a nonce and prerendered pages a hash. A script of the site's own in <svelte:head> (a colour-mode script, say) is then blocked unless you allow it:

  • By its hash, in script-src (csp: { mode: 'auto', directives: { 'script-src': ['self', 'sha256-…'] } }). The hash is of the script's text exactly as written, so change it whenever the script changes. openssl dgst -sha256 -binary script.js | openssl base64 gives the value after sha256-. Prerendered pages need this way.
  • In src/app.html, with SvelteKit's nonce, instead of in <svelte:head>. A nonce is made per request, so this suits pages rendered per request:
    <head>
      <script nonce="%sveltekit.nonce%">
        document.documentElement.dataset.theme = localStorage.getItem('theme') ?? 'light'
      </script>
      %sveltekit.head%
    </head>
    

Styles work the same way under style-src. Without kit.csp the preview answers with an error that names it and links here.

@shadestack/nuxt

Vue 3, for Nuxt.

// nuxt.config.ts
export default defineNuxtConfig({ modules: ['@shadestack/nuxt/module'] })
<!-- pages/[...slug].vue -->
<script setup lang="ts">
const route = useRoute()
// `useRequestFetch` passes the visitor's cookie on when Nuxt renders on the server, so a server island sees them.
const requestFetch = useRequestFetch()
const { data } = await useAsyncData(`page:${route.path}`, () => requestFetch('/api/shade-page', { query: { path: route.path } }))
</script>

<template>
  <main><ShadeTree v-if="data" :result="data.result" :interactions="data.page.interactions" /></main>
</template>

with a server route that reads SHADE (the token stays on the server):

// server/api/shade-page.get.ts
import { findPage, resolvePage, shadeFromEnv, shadeNoStore } from '@shadestack/nuxt'

export default defineEventHandler(async (event) => {
  const shade = shadeFromEnv()
  const path = String(getQuery(event).path ?? '')
  const [site, page] = await Promise.all([shade.site(), findPage(shade, path.split('/').filter(Boolean))])
  if (!page) throw createError({ statusCode: 404 })
  const result = resolvePage(input) // the page's tree, components, data and language, as above
  // A page that is the visitor's own: its JSON with `Cache-Control: private, no-store`, kept out of shared caches.
  return { site, page, result: shadeNoStore(event, result) }
})
  • The module registers <ShadeTree> everywhere, adds @shadestack/render/render.css (off with shade: { css: false }), and lets Nuxt compile SHADE's packages. It also tells Vue that SHADE's wrappers and widgets are custom elements (SHADE_ELEMENTS: @shadestack/render's SHADE_ELEMENT_TAGS, shade-island, shade-code, shade-icon and the widgets of WIDGET_TAGS, and no other shade- tag, so <shade-tree> and a site's own Shade… components stay components).
  • ShadeTree and shadeHead for the new editor's pages (@shadestack/render); resolve the page in the server route. ShadeTree sends a page that is the visitor's own with Cache-Control: private, no-store, and shadeNoStore(event, result) sends the server route's JSON so, which the browser fetches on a client-side navigation. Fetch it with useRequestFetch(), so the visitor's cookie reaches the route during server rendering. With :interactions, ShadeTree starts the page's interactions in the browser once it is mounted, and again with the next page's.
  • A prerendered page's server islands (deferred): in the server route, resolve with serverIslands: 'defer' and return result: await deferServerIslands(result). The module adds the island route itself (GET /shade-island, under app.baseURL) and tells ShadeTree the base path; set SHADE_ISLAND_SECRET at build time and on the server.
  • The preview route (preview and rebuild): the module's server module gives the page at /preview (under app.baseURL) its headers and, outside development, its policy, from what Nuxt wrote itself: the head and what Nuxt appends to the body (its payload and config), never the rendered body. The preview is rendered as one answer: a preview with streaming on in routeRules is refused. The page reads the draft from a server route that sends its JSON with the preview's headers (shadePreviewHeaders(event)):
    // server/api/shade-preview.get.ts
    import { readPreview, shadeFromEnv, shadePreviewHeaders } from '@shadestack/nuxt'
    import { renderPublishedPage } from '@shadestack/client/render'
    
    export default defineEventHandler(async (event) => {
      shadePreviewHeaders(event)
      const shade = shadeFromEnv()
      const preview = await readPreview(shade, getQuery(event).token)
      if (!('page' in preview)) throw createError({ statusCode: preview.status, statusMessage: preview.message })
      const { result } = await renderPublishedPage(preview.page, { client: shade })
      return { page: preview.page, result }
    })
    

    pages/preview.vue fetches it with useRequestFetch() and useAsyncData, passing route.query.token, throws createError({ …, fatal: true }) on an error, and renders ShadeTree like the page above.
  • The rebuild route: the module adds POST /shade-rebuild, which takes SHADE_REBUILD_TOKEN and clears what Nitro cached of the site's pages: the route rules' cached answers (cache, swr, isr on Nitro's own storage) and the cached handlers (defineCachedEventHandler, such as a cached /api/shade-page). The next visit reads SHADE again. Other cached functions stay. A prerendered site (nuxt generate) and a host's own ISR cache need the host's deploy hook instead.

Starter: starters/nuxt. It reads SHADE through server routes of its own (server/api/), so the token stays on the server.