Files
sweet/example/pages/_render.ts
T
Luca Casonato 7cf4ca07ed feat: streaming rendering with suspense (#59)
This commit introduces support for streaming server side rendering using
<Suspense>.
2021-09-26 01:21:02 +02:00

19 lines
588 B
TypeScript

// This module adds twind support.
import { virtualSheet } from "https://esm.sh/twind/sheets";
import { setup } from "../deps.ts";
import { RenderContext, RenderFn } from "../server_deps.ts";
const sheet = virtualSheet();
sheet.reset();
setup({ sheet });
export function render(ctx: RenderContext, render: RenderFn) {
const snapshot = ctx.state.get("twindSnapshot") as unknown[] | null;
sheet.reset(snapshot || undefined);
render();
ctx.styles.splice(0, ctx.styles.length, ...sheet.target);
const newSnapshot = sheet.reset();
ctx.state.set("twindSnapshot", newSnapshot);
}