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:
@@ -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>`;
|
||||
}
|
||||
Reference in New Issue
Block a user