Skip to content

Commit

Permalink
Add support for React 19
Browse files Browse the repository at this point in the history
This adds support for React 19 types, by removing the dependency on the
types provided by hast-util-to-jsx-runtime, thus removing the dependency
on the JSX global namespace.
  • Loading branch information
remcohaszing committed Jan 2, 2025
1 parent 27d3949 commit ac91753
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @typedef {import('hast-util-to-jsx-runtime').ExtraProps} ExtraProps
* @typedef {import('./lib/index.js').AllowElement} AllowElement
* @typedef {import('./lib/index.js').Components} Components
* @typedef {import('./lib/index.js').ExtraProps} ExtraProps
* @typedef {import('./lib/index.js').Options} Options
* @typedef {import('./lib/index.js').UrlTransform} UrlTransform
*/
Expand Down
17 changes: 14 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* @import {Element, ElementContent, Nodes, Parents, Root} from 'hast'
* @import {Components as JsxRuntimeComponents} from 'hast-util-to-jsx-runtime'
* @import {ReactElement} from 'react'
* @import {ComponentProps, ElementType, ReactElement} from 'react'
* @import {Options as RemarkRehypeOptions} from 'remark-rehype'
* @import {BuildVisitor} from 'unist-util-visit'
* @import {PluggableList} from 'unified'
Expand All @@ -21,7 +20,16 @@
*/

/**
* @typedef {Partial<JsxRuntimeComponents>} Components
* @typedef ExtraProps
* Extra fields we pass.
* @property {Element | undefined} [node]
* passed when `passNode` is on.
*/

/**
* @typedef {{
* [Key in Extract<ElementType, string>]?: ElementType<ComponentProps<Key> & ExtraProps>
* }} Components
* Map tag names to components.
*/

Expand Down Expand Up @@ -225,6 +233,9 @@ export function Markdown(options) {

return toJsxRuntime(hastTree, {
Fragment,
// @ts-expect-error
// React components are allowed to return numbers,
// but not according to the types in hast-util-to-jsx-runtime
components,
ignoreInvalidStyle: true,
jsx,
Expand Down

0 comments on commit ac91753

Please sign in to comment.