Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React 19 Type Compatibility #643

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gentle-bikes-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'markdown-to-jsx': patch
---

Use `ReactNode` instead of `ReactChild` for React 19 compatibility
Binary file not shown.
Binary file not shown.
Binary file added .yarn/cache/fsevents-patch-19706e7e35-10.zip
Binary file not shown.
6 changes: 6 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ enableGlobalCache: false
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.5.1.cjs

supportedArchitectures:
os:
- linux
- win32
- darwin
14 changes: 7 additions & 7 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ function reactFor(render) {
return function patchedRender(
ast: MarkdownToJSX.ParserResult | MarkdownToJSX.ParserResult[],
state: MarkdownToJSX.State = {}
): React.ReactChild[] {
): React.ReactNode[] {
if (Array.isArray(ast)) {
const oldKey = state.key
const result = []
Expand Down Expand Up @@ -1094,7 +1094,7 @@ function createRenderer(
ast: MarkdownToJSX.ParserResult,
render: MarkdownToJSX.RuleOutput,
state: MarkdownToJSX.State
): React.ReactChild {
): React.ReactNode {
const renderer = rules[ast.type].render as MarkdownToJSX.Rule['render']

return userRender
Expand Down Expand Up @@ -2292,7 +2292,7 @@ export namespace MarkdownToJSX {
*/
render: RuleOutput,
state?: MarkdownToJSX.State
) => React.ReactChild
) => React.ReactNode
}

export type Rules = {
Expand Down Expand Up @@ -2321,8 +2321,8 @@ export namespace MarkdownToJSX {
createElement: (
tag: Parameters<CreateElement>[0],
props: React.JSX.IntrinsicAttributes,
...children: React.ReactChild[]
) => React.ReactChild
...children: React.ReactNode[]
) => React.ReactNode

/**
* The library automatically generates an anchor tag for bare URLs included in the markdown
Expand Down Expand Up @@ -2414,14 +2414,14 @@ export namespace MarkdownToJSX {
*/
renderRule: (
/** Resume normal processing, call this function as a fallback if you are not returning custom JSX. */
next: () => React.ReactChild,
next: () => React.ReactNode,
/** the current AST node, use `RuleType` against `node.type` for identification */
node: ParserResult,
/** use as `renderChildren(node.children)` for block nodes */
renderChildren: RuleOutput,
/** contains `key` which should be supplied to the topmost JSX element */
state: State
) => React.ReactChild
) => React.ReactNode

/**
* Override the built-in sanitizer function for URLs, etc if desired. The built-in version is available as a library export called `sanitizer`.
Expand Down
Loading