Skip to content

Commit

Permalink
React 19 Type Compatibility (#643)
Browse files Browse the repository at this point in the history
* Ensure cache supports windows, linux, osx

* Widen ReactChild to ReactNode for React 19 type compatibility

* changeset
  • Loading branch information
mrginglymus authored Dec 18, 2024
1 parent 4fa87d8 commit 52a727c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
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

0 comments on commit 52a727c

Please sign in to comment.