Skip to content

Commit

Permalink
refactor: support async renderToString (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa authored Nov 17, 2023
1 parent 562d254 commit 0c8a688
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const createApp = <E extends Env>(options: ServerOptions<E>): Hono<E> =>
}
}

const content = render(innerContent)
const content = await render(innerContent)

if (typeof content === 'string') {
if (defaultLayout || layouts?.length) {
Expand All @@ -158,7 +158,7 @@ export const createApp = <E extends Env>(options: ServerOptions<E>): Hono<E> =>
if (options.setDefaultRenderer === true) {
app.use('*', async (c, next) => {
c.setRenderer(async (node) => {
return createResponse(c, render(node))
return createResponse(c, await render(node))
})
await next()
})
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type Methods = 'GET' | 'POST' | 'PUT' | 'DELETE'
/** JSX */
export type CreateElement = (type: any, props: any, ...children: any[]) => Node
export type FragmentType = any
export type RenderToString<N = Node> = (node: N) => string
export type RenderToString<N = Node> = (node: N) => string | Promise<string>
export type RenderToReadableStream<N = Node> = (node: N, options?: any) => Promise<ReadableStream>
export type Hydrate = (children: Node, parent: Element) => void

Expand Down

0 comments on commit 0c8a688

Please sign in to comment.