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 Dec 20, 2024
1 parent c582e3b commit 4999108
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 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
18 changes: 14 additions & 4 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,8 +20,16 @@
*/

/**
* @typedef {Partial<JsxRuntimeComponents>} Components
* Map tag names to 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
*/

/**
Expand Down Expand Up @@ -225,6 +232,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 4999108

Please sign in to comment.