Skip to content
Myr

feat(jsx-renderer): `docType` option (#1621)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* feat(jsx-renderer): `docType` option * denoify * refactor Co-authored-by: Taku Amano <taku@taaas.jp> * denoify ---------

authored by Yusuke Wada · committed by GitHub · parent 3ead9a7 · Browse files · 3 files+97 added−20 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Taku Amano <taku@taaas.jp>

Diff stats

3 files+97 added−20 removed

  • tests:+49 added−0 removed
  • other:+48 added−20 removed

3 files+97 added−20 removed

modified:deno_dist/middleware/jsx-renderer/index.ts+24 added-10 removed
modified:src/middleware/jsx-renderer/index.test.tsx+49 added
modified:src/middleware/jsx-renderer/index.ts+24 added-10 removed
8 unmodified lines
9type PropsForRenderer = [...Required<Parameters<Renderer>>] extends [unknown, infer Props]10 ? Props11 : unknown1213type RendererOptions = {14 docType?: boolean | string15}1617const createRenderer =18 (c: Context, component?: FC<PropsForRenderer>, options?: RendererOptions) =>19 (children: JSXNode, props: PropsForRenderer) => {20 const docType =21 typeof options?.docType === 'string'22 ? options.docType23 : options?.docType === true24 ? '<!DOCTYPE html>'25 : ''2614 (c: Context, component?: FC<PropsForRenderer>) => (children: JSXNode, props: PropsForRenderer) =>15 /* eslint-disable @typescript-eslint/no-explicit-any */16 c.html(17 jsx(18 RequestContext.Provider,19 { value: c },20 (component ? component({ children, ...(props || {}) }) : children) as any21 ) as any27 return c.html(28 (docType +29 /* eslint-disable @typescript-eslint/no-explicit-any */30 jsx(31 RequestContext.Provider,32 { value: c },33 (component ? component({ children, ...(props || {}) }) : children) as any34 )) as any35 )36 }3738export const jsxRenderer =25 (component?: FC<PropsForRenderer>): MiddlewareHandler =>39 (component?: FC<PropsForRenderer>, options?: RendererOptions): MiddlewareHandler =>40 (c, next) => {41 /* eslint-disable @typescript-eslint/no-explicit-any */28 c.setRenderer(createRenderer(c, component) as any)42 c.setRenderer(createRenderer(c, component, options) as any)43 return next()44 }4546export const useRequestContext = <
10 unmodified lines