-
-
Notifications
You must be signed in to change notification settings - Fork 892
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
Add support for React 19 #879
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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' | ||
|
@@ -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. | ||
*/ | ||
|
||
|
@@ -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 | ||
Comment on lines
+236
to
+238
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this related to syntax-tree/hast-util-to-jsx-runtime#6 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somewhat yes. But also apparently There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to solve such things instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, but that issue has been proven hard to resolve upstream. (If it can be resolved upstream at all.) This |
||
components, | ||
ignoreInvalidStyle: true, | ||
jsx, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this type is not equivalent to the previous
Components
.But this is listed as a patch.
Is it intentional that you remove
keyof JSX.IntrinsicElements
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ElementType
includesJSX.IntrinsicElements
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@remcohaszing No, I mean
keyof
? Does this allowb: 'i'
. I assume not, becausei
or all other element names are not related to props?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does! And there’s also a pre-existing test which covers this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird, I do not see it in the source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
react-markdown/test.jsx
Line 523 in 27d3949
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right no that, I meant in the
@types/react
codeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like it could be a bug that
@types/react
supports this today — that they could remove it somewhere in the futureThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure where it happens but when I change that line to
h1: 'x-y'
we get a type error — which indicates that I should worry less because it is type checked — even though the types should likely allow custom elements like that.