feat: render function returns string (#89)

This commit is contained in:
Leo Kettmeir
2022-02-15 12:28:09 +01:00
committed by GitHub
parent d334b53320
commit 15f73e3274
3 changed files with 33 additions and 21 deletions
+5 -3
View File
@@ -26,7 +26,7 @@ export interface RenderOptions {
error?: unknown;
}
export type RenderFn = () => void;
export type RenderFn = () => string;
export class RenderContext {
#id: string;
@@ -178,10 +178,11 @@ export async function* render(
function render() {
try {
body = renderToString(vnode);
return body;
} catch (e) {
if (e && e.then) {
promise = e;
return;
return "";
}
throw e;
}
@@ -318,10 +319,11 @@ export async function suspenseRender(
function render() {
try {
body = renderToString(vnode);
return body;
} catch (e) {
if (e && e.then) {
promise = e;
return;
return "";
}
throw e;
}
+8
View File
@@ -0,0 +1,8 @@
import { RenderContext, RenderFn } from "../../../server.ts";
export function render(_ctx: RenderContext, render: RenderFn) {
const body = render();
if (typeof body !== "string") {
throw new Error("body is missing");
}
}
+20 -18
View File
@@ -5,30 +5,32 @@
import * as $0 from "./pages/index.tsx";
import * as $1 from "./pages/static.tsx";
import * as $2 from "./pages/intercept_args.tsx";
import * as $3 from "./pages/props/[id].tsx";
import * as $4 from "./pages/failure.ts";
import * as $5 from "./pages/_middleware.ts";
import * as $6 from "./pages/books/[id].tsx";
import * as $7 from "./pages/api/get_only.ts";
import * as $8 from "./pages/_500.tsx";
import * as $9 from "./pages/intercept.tsx";
import * as $10 from "./pages/_404.tsx";
import * as $11 from "./pages/[name].tsx";
import * as $3 from "./pages/_render.ts";
import * as $4 from "./pages/props/[id].tsx";
import * as $5 from "./pages/failure.ts";
import * as $6 from "./pages/_middleware.ts";
import * as $7 from "./pages/books/[id].tsx";
import * as $8 from "./pages/api/get_only.ts";
import * as $9 from "./pages/_500.tsx";
import * as $10 from "./pages/intercept.tsx";
import * as $11 from "./pages/_404.tsx";
import * as $12 from "./pages/[name].tsx";
const routes = {
pages: {
"./pages/index.tsx": $0,
"./pages/static.tsx": $1,
"./pages/intercept_args.tsx": $2,
"./pages/props/[id].tsx": $3,
"./pages/failure.ts": $4,
"./pages/_middleware.ts": $5,
"./pages/books/[id].tsx": $6,
"./pages/api/get_only.ts": $7,
"./pages/_500.tsx": $8,
"./pages/intercept.tsx": $9,
"./pages/_404.tsx": $10,
"./pages/[name].tsx": $11,
"./pages/_render.ts": $3,
"./pages/props/[id].tsx": $4,
"./pages/failure.ts": $5,
"./pages/_middleware.ts": $6,
"./pages/books/[id].tsx": $7,
"./pages/api/get_only.ts": $8,
"./pages/_500.tsx": $9,
"./pages/intercept.tsx": $10,
"./pages/_404.tsx": $11,
"./pages/[name].tsx": $12,
},
baseUrl: import.meta.url,
};