feat: support suspending during SSR and useData (#27)

This commit adds support for suspending during JIT SSR rendering.
Additionally this PR adds `useData` support. This hook is triggered
during JIT render and can be used to fetch data. This data is sent to
the client and returned there from calls to useData too.
This commit is contained in:
Luca Casonato
2021-06-11 13:59:55 +02:00
committed by GitHub
parent ae1e311eb8
commit 56baffa96d
13 changed files with 226 additions and 53 deletions
-37
View File
@@ -1,37 +0,0 @@
import { renderToString } from "./deps.ts";
import * as rt from "../runtime/deps.ts";
import { Page } from "./types.ts";
export interface RenderOptions {
page: Page;
imports: string[];
preloads: string[];
params: Record<string, string>;
}
export function render(options: RenderOptions): string {
const props = { params: options.params };
const propsStr = JSON.stringify(props);
const body = renderToString(rt.h(options.page.component, props));
return `<!DOCTYPE html>
<html>
<head>
${
options.preloads.map((src) => `<link rel="modulepreload" href="${src}">`)
.join(
"\n ",
)
}
${
options.imports.map((src) => `<script src="${src}" type="module"></script>`)
.join(
"\n ",
)
}
</head>
<body>
${body}
<script id="__FRSH_PROPS" type="application/json">${propsStr}</script>
</body>
</html>`;
}