Skip to content

Commit e610d1d

Browse files
authoredFeb 12, 2025··
fix type of Navbar.children, should be ReactNode, not ReactElement (#4201)
* allow change `nextThemes.forcedTheme` prop * afix * fix * now * now
1 parent 7ae958f commit e610d1d

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed
 

‎.changeset/six-ants-rhyme.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"nextra-theme-docs": patch
3+
---
4+
5+
fix type of `Navbar.children`, should be `ReactNode`, not `ReactElement`

‎packages/nextra-theme-docs/src/components/navbar/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import cn from 'clsx'
33
import NextLink from 'next/link'
44
import { Anchor } from 'nextra/components'
55
import { DiscordIcon, GitHubIcon } from 'nextra/icons'
6-
import { element } from 'nextra/schemas'
6+
import { element, reactNode } from 'nextra/schemas'
77
import type { FC } from 'react'
88
import { z } from 'zod'
99
import { fromZodError } from 'zod-validation-error'
1010
import { ClientNavbar } from './index.client'
1111

1212
const propsSchema = z.strictObject({
13-
children: element.optional(),
13+
children: reactNode.optional(),
1414
logoLink: z.union([z.string(), z.boolean()]).default(true),
1515
logo: element,
1616
projectLink: z.string().optional(),

‎packages/nextra/src/server/schemas.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ProcessorOptions } from '@mdx-js/mdx'
22
import type { MathJax3Config } from 'better-react-mathjax'
3-
import type { ReactElement } from 'react'
3+
import type { ReactElement, ReactNode } from 'react'
44
import { isValidElement } from 'react'
55
import type { Options as RehypeKatexOptions } from 'rehype-katex'
66
import type { Options as RehypePrettyCodeOptions } from 'rehype-pretty-code'
@@ -72,6 +72,12 @@ export const element = z.custom<ReactElement<Record<string, unknown>>>(
7272
isValidElement,
7373
{ message: 'Must be React.ReactElement' }
7474
)
75+
export const reactNode = z.custom<ReactNode>(
76+
data =>
77+
isValidElement(data) ||
78+
(Array.isArray(data) && data.every(value => isValidElement(value))),
79+
{ message: 'Must be React.ReactNode' }
80+
)
7581

7682
export const stringOrElement = z.union([z.string(), element])
7783

0 commit comments

Comments
 (0)
Please sign in to comment.