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

Add support for React 19 #879

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add support for React 19 #879

wants to merge 3 commits into from

Conversation

remcohaszing
Copy link
Member

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything or linked relevant results below
  • I made sure the docs are up to date
  • I included tests (or that’s not needed)

Description of changes

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.

Unfortunately the current setup doesn’t really allow testing the types against multiple React versions. #838 would enable that.

Closes #877

Having them in the same block, can be problematic sometimes. For
example when they contain `@template` tags.
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.
@remcohaszing remcohaszing added 🐛 type/bug This is a problem ☂️ area/types This affects typings 👶 semver/patch This is a backwards-compatible fix 🤞 phase/open Post is being triaged manually labels Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

index.js:4

  • [nitpick] The re-addition of the ExtraProps typedef seems redundant and could be confusing. Consider removing it if not necessary.
* @typedef {import('./lib/index.js').ExtraProps} ExtraProps
Copy link
Member

@ChristianMurphy ChristianMurphy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @remcohaszing

Comment on lines +236 to +238
// @ts-expect-error
// React components are allowed to return numbers,
// but not according to the types in hast-util-to-jsx-runtime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat yes. But also apparently hast-util-to-jsx-runtime doesn’t support JSX.ElementType, which JSX runtimes may optionally define. That adds another complexity on top of that issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to solve such things instead of ts-expect-error

@bluepeter
Copy link

Let's make this happen!

@wooorm
Copy link
Member

wooorm commented Jan 1, 2025

Why does Copilot review things?

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

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?

*
*/

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with these changes, but it would be good to have different commits for things of varying importance. This commit/PR is very important, many humans will look at the change, and see this mix of important/trivial.
Not blocking, but like: feel free to commit such refactors things directly to main (Refactor code-style), and use a PR for things that need eyes on them!

Comment on lines +236 to +238
// @ts-expect-error
// React components are allowed to return numbers,
// but not according to the types in hast-util-to-jsx-runtime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to solve such things instead of ts-expect-error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☂️ area/types This affects typings 🤞 phase/open Post is being triaged manually 👶 semver/patch This is a backwards-compatible fix 🐛 type/bug This is a problem
Development

Successfully merging this pull request may close these issues.

React 19 support
4 participants