diff --git a/.changeset/curly-fans-rhyme.md b/.changeset/curly-fans-rhyme.md
new file mode 100644
index 00000000..85808bcb
--- /dev/null
+++ b/.changeset/curly-fans-rhyme.md
@@ -0,0 +1,5 @@
+---
+'@hono/react-renderer': minor
+---
+
+The `doctype` option defaults to true
diff --git a/packages/react-renderer/src/react-renderer.ts b/packages/react-renderer/src/react-renderer.ts
index a36d7c7b..0a9943b4 100644
--- a/packages/react-renderer/src/react-renderer.ts
+++ b/packages/react-renderer/src/react-renderer.ts
@@ -51,9 +51,9 @@ const createRenderer =
const docType =
typeof options?.docType === 'string'
? options.docType
- : options?.docType === true
- ? ''
- : ''
+ : options?.docType === false
+ ? ''
+ : ''
const body =
docType + renderToString(React.createElement(RequestContext.Provider, { value: c }, node))
return c.html(body)
diff --git a/packages/react-renderer/test/react-renderer.test.tsx b/packages/react-renderer/test/react-renderer.test.tsx
index 07b42926..81a649bb 100644
--- a/packages/react-renderer/test/react-renderer.test.tsx
+++ b/packages/react-renderer/test/react-renderer.test.tsx
@@ -36,7 +36,7 @@ describe('Basic', () => {
expect(res).not.toBeNull()
expect(res.status).toBe(200)
expect(await res.text()).toBe(
- '
Titlehttp://localhost/
'
+ 'Titlehttp://localhost/
'
)
})
@@ -54,7 +54,7 @@ describe('Basic', () => {
const res = await app.request('http://localhost/')
expect(res).not.toBeNull()
expect(res.status).toBe(200)
- expect(await res.text()).toBe('http://localhost/
')
+ expect(await res.text()).toBe('http://localhost/
')
})
it('nested layout with Layout', async () => {
@@ -109,14 +109,14 @@ describe('Basic', () => {
expect(res).not.toBeNull()
expect(res.status).toBe(200)
expect(await res.text()).toBe(
- 'Nestedhttp://localhost/nested
'
+ 'Nestedhttp://localhost/nested
'
)
res = await app.request('http://localhost/nested/nested2')
expect(res).not.toBeNull()
expect(res.status).toBe(200)
expect(await res.text()).toBe(
- 'Nested2'
+ 'Nested2'
)
})
@@ -142,6 +142,28 @@ describe('Basic', () => {
expect(await res.text()).toBe('Hello
')
})
+ it('Should return a content without a doctype', async () => {
+ const app = new Hono()
+ app.use(
+ '*',
+ reactRenderer(
+ ({ children }) => {
+ return (
+
+ {children}
+
+ )
+ },
+ { docType: false }
+ )
+ )
+ app.get('/', (c) => c.render(Hello
, { title: 'Title' }))
+ const res = await app.request('/')
+ expect(res).not.toBeNull()
+ expect(res.status).toBe(200)
+ expect(await res.text()).toBe('Hello
')
+ })
+
it('Should return a custom doctype', async () => {
const app = new Hono()
app.use(