Skip to content

Conversation

@DiegoAndai
Copy link
Contributor

@DiegoAndai DiegoAndai commented Jul 5, 2024

What: Replace global JSX with React.JSX

Why: Prepare for upcoming @types/react version which removes global JSX

How: Upgrade @types/react to ^18.2.6 which is the version that introduces React.JSX and use it to replace global JSX

Checklist:

  • Documentation N/A
  • Tests N/A
  • Code complete N/A
  • Changeset

Additional comments:

  • I've updated the site's @types/react as well to match the other packages.

Let me know if there's anything I might have missed.

@changeset-bot
Copy link

changeset-bot bot commented Jul 5, 2024

🦋 Changeset detected

Latest commit: 7b6928e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@emotion/styled Patch
@emotion/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 5, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@DiegoAndai
Copy link
Contributor Author

DiegoAndai commented Jul 5, 2024

I'm looking into the CI failures

@DiegoAndai DiegoAndai changed the title React 18.2 types Replace global JSX with React.JSX Jul 5, 2024
@DiegoAndai
Copy link
Contributor Author

DiegoAndai commented Jul 5, 2024

@Andarist
Copy link
Member

Andarist commented Jul 6, 2024

@emmatown 18.2.6 was published at 2023-05-06T11:32:52.704Z (over a year ago). I think we might have to go forward with this PR to improve compatibility with the upcoming React 19 for Emotion 11. This is kinda a breaking change for people who might be using older @types/react versions... but I don't think we have any alternative way. It's rather hard to reliably check at type level if React.JSX exists or not to branch our logic.

@emmatown
Copy link
Member

emmatown commented Jul 8, 2024

Hmmm, that's seems unfortunate. It doesn't seem to hard branch (with @ts-ignore of course), curious where it'd be unreliable?

@Andarist
Copy link
Member

Andarist commented Jul 8, 2024

We can’t trust error types that result from ts-ignore: microsoft/TypeScript#58960

@Andarist
Copy link
Member

Andarist commented Jul 9, 2024

@emmatown wdyt?

@emmatown
Copy link
Member

emmatown commented Jul 9, 2024

Wouldn't something like this work without being susceptible to any issues like that? FunctionComponent no longer has a second legacy context parameter in React 19 types which we can check without any @ts-ignore stuff (there are probably other ways to check, this was just the first I tried) and then we use the right thing depending on the version and only those have @ts-ignore but the side where @ts-ignore does something is never used

type JSXElement = 2 extends Parameters<React.FunctionComponent<any>>['length']
  ? // @ts-ignore
    JSX.Element
  : // @ts-ignore
    React.JSX.Element

@Andarist Andarist changed the title Replace global JSX with React.JSX Improved compatibility with the upcoming @types/react for React 19 Jul 17, 2024
@Andarist
Copy link
Member

Do u always have to have the answer? 😉

I applied the suggestion. I think this should be good to go now.

@emmatown emmatown merged commit d1994c4 into emotion-js:main Jul 19, 2024
@github-actions github-actions bot mentioned this pull request Jul 19, 2024
@DiegoAndai DiegoAndai deleted the react-18.2-types branch July 19, 2024 16:02
@emmatown emmatown mentioned this pull request Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants