-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[core] Bump React to 19 #42824
[core] Bump React to 19 #42824
Conversation
@aarongarciah, we're working on the Emotion type fixes alongside the Emotion maintainers: emotion-js/emotion#3206 The next issue I'm facing is with the following packages:
Neither of these are up to date, and I don't think it's worth it for us to to try and update them like we did with Emotion:
So I think we should deprecate |
@DiegoAndai I think this makes sense.
Can you expand a bit? I assume you're talking about the top level package.json resolutions. Can we add a |
Netlify deploy preview
ImageListItem: parsed: -1.34% 😍, gzip: -1.20% 😍 Bundle size reportDetails of bundle changes (Toolpad) |
Hey @Janpot @michaldudak, I need your help with this. Could you check the branch and see if you can figure it out? We have two packages which are not compatible with React 19 types:
Important note: Focus only on the Here are the errors I'm getting:
|
Also, I would expect this line to exclude the |
Going to sleep now, so can't help much, but got some points that might help you:
probably
Resolutions is for "pnpm": {
"overrides": {
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0"
}
}, |
@JCQuintas
|
oops didn't know that. 🙃 |
Yes, |
As far as I know there is no other way around this right now, since you can't select which libs to skip in typescript. Since we are already doing the "resolutions" change, that is a "trust me" moment. Sure the lib check might help catching so issues, but if the types are different, then you will definitely get an error with the only opt out I know being |
@@ -267,7 +267,7 @@ export function useSlider(parameters: UseSliderParameters): UseSliderReturnValue | |||
|
|||
const [focusedThumbIndex, setFocusedThumbIndex] = React.useState(-1); | |||
|
|||
const sliderRef = React.useRef<HTMLSpanElement>(); | |||
const sliderRef = React.useRef<HTMLSpanElement>(undefined); |
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.
Shouldn't it be?
const sliderRef = React.useRef<HTMLSpanElement>(undefined); | |
const sliderRef = React.useRef<HTMLSpanElement>(null); |
It should be an immutable ref here. It looks like I have missed this one in #38762. We could make a PR just for it.
I dove a bit into this in mui/mui-x#11847.
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.
Oh, ok, it's changing: DefinitelyTyped/DefinitelyTyped#64896, so
const sliderRef = React.useRef<HTMLSpanElement>(undefined); | |
const sliderRef = React.useRef<HTMLSpanElement | null>(null); |
?
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 think | null
is the correct approach, yeah #42881 (comment)
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, then +1 to udpate all the codebase with this. We don't have to correlate it with React 19..it seems that it would work with all versions.
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.
For posterity, in React 19:
React.useRef
requires an initial value. There's no need to do| null
when the initial value isnull
(same forundefined
). You can still do it if you want to be more explicit. It goes like this (pseudo-code):const ref = React.useRef<T>(null)
->ref
isT | null
const ref = React.useRef<T>(undefined)
->ref
isT | undefined
const ref = React.useRef<T>(T)
->ref
isT
React.MutableRefObject
has been deprecated.React.RefObject
is used for all cases now, and it's always mutable. UnlikeReact.Ref
, we need to explicitly make the ref object nullable:React.RefObject<T | null>
.
(more info in the React 19 types PR)
I'll try to take a look at this over the week, but what I can already say about resolutions is that I don't think of it as a tool we can use to solve this problem. As far as I'm aware, as a package author, you can't enforce how your transitive dependencies are resolved by the consumers of your package. So we'd fix the problem in our repo, but I believe our users would still have it. I think we shouldn't use resolutions/overrides, unless it's scoped to the docs workspace. edit:
Not 100% clear to me yet what exactly is going on here. It's referencing |
Thanks for taking a look @Janpot
With this, do you mean that we shouldn't have I tried the patch approach but I still get the same errors 😓 The issue here is that I'm not able to figure out how to make the pnpm workspace like this:
Do you see a way of making it work like that? |
This feels a bit too bold. I could see a lot of people using styled-components and not care about types, as well as upgrading Material UI to v6 without upgrading React or Next.js. If we can ignore the types for those packages, I think it would be good enough. |
I'm taking a closer look today
Correct, in fact we shouldn't have
|
It's working locally 👍🏼 I'll need to check the CI builds "killed" signal issue, but it should also work in CI. |
Given the amount of dependency changes, When the time comes to merge this, we can change all test containers to |
const { container } = render(<Data />); | ||
|
||
expect(container.firstChild.textContent).to.equal('light:2'); // 2 because of double render within strict mode | ||
expect(container.firstChild.textContent).to.equal('light'); | ||
expect(effectRunCount).to.equal(reactMajor >= 19 ? 2 : 3); |
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.
This test was recently added, that's why we didn't cover it before in this PR.
The previous approach didn't work with React 19, probably due to the changes to strict mode. The difference in events between 18 and 19 is the following:
render
render
run effect
-run effect (this one doesn't run in React 19)
render
render
run effect
And for both, the last effect run wasn't being registered in the rendered content. That's why with React 18 the result was light:2
even though the effect runs 3 times. For React 19, the effect is runs 2 times.
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.
cc: @siriwatknp
Moved to #44672 as Argos was not working due to this branch originating from the |
Merged #44672 |
Part of #42381
This PR serves as a sandbox to check how many issues we have left to solve to support React 19.