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
+3 -3
View File
@@ -7,7 +7,7 @@ import { INTERNAL_PREFIX } from "./constants.ts";
import { JS_PREFIX } from "./constants.ts";
import { BUILD_ID } from "./constants.ts";
import { ApiRoute, Page } from "./types.ts";
import { render } from "./render.ts";
import { render } from "./render.tsx";
export class ServerContext {
#pages: Page[];
@@ -77,11 +77,11 @@ export class ServerContext {
for (const page of this.#pages) {
const bundlePath = `/${page.name}.js`;
const imports = [bundleAssetUrl(bundlePath)];
routes[page.route] = (_, match) => {
routes[page.route] = async (_, match) => {
const preloads = this.#bundler.getPreloads(bundlePath).map(
bundleAssetUrl,
);
const body = render({
const body = await render({
page,
imports,
preloads,