feat: render function returns string (#89)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user