-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
[react] Make all refs mutable by default #64896
base: master
Are you sure you want to change the base?
Conversation
dc13350
to
07075da
Compare
ffff287
to
95c7b2e
Compare
Inspecting the JavaScript source for this package found some properties that are not in the .d.ts files. babel-plugin-react-html-attrs (unpkg)was missing the following properties:
gatsbyjs__reach-router (unpkg)was missing the following properties:
as well as these 34 other properties...pick, resolve, shallowCompare, startsWith, useBaseContext, useLocationContext, useNavigate, validateRedirect, BaseContext, LocationContext, insertParams, match, navigate, pick, resolve, shallowCompare, startsWith, useBaseContext, useLocationContext, useNavigate, validateRedirect, BaseContext, LocationContext, insertParams, match, navigate, pick, resolve, shallowCompare, startsWith, useBaseContext, useLocationContext, useNavigate, validateRedirect reach__router (unpkg)was missing the following properties:
react-bootstrap-typeahead (unpkg)was missing the following properties:
as well as these 5 other properties...menuItemContainer, useItem, withItem, tokenContainer, withToken react-map-gl (unpkg)was missing the following properties:
react-onclickoutside (unpkg)was missing the following properties:
react (unpkg)was missing the following properties:
tuya-panel-kit (unpkg)was missing the following properties:
wordpress__components (unpkg)was missing the following properties:
as well as these 17 other properties...Line, SearchControl, TextHighlight, ToolbarDropdownMenu, ToolbarItem, useBaseControlProps, CustomGradientPicker, DuotonePicker, DuotoneSwatch, GradientPicker, GuidePage, Line, SearchControl, TextHighlight, ToolbarDropdownMenu, ToolbarItem, useBaseControlProps wordpress__rich-text (unpkg)was missing the following properties:
|
I kept MutableRefObject around so that anyone using RefObject in their application code would not have the type change from under them and represented RefObject with MutableRefObject. It seemed like a cleaner deprecation path. I also think if we are making breaking changes for React 19, we should not allow the zero argument version of |
We track this separately in #64920. This PR is not stacking all React 19 changes.
Which other cases?
#64920 will propose its non-existent i.e. only |
13f70c4
to
c018004
Compare
c018004
to
610918c
Compare
610918c
to
9f7d98e
Compare
Ready for review but won't be merged here and rather in a PR for 19 stacking all changes from #64451
Closes #64855
Closes #64772
Fixes first gotcha in https://twitter.com/mattpocockuk/status/1636098722982404096 (second one will be fixed in #64920).
RefObject
is no longer considered a ref managed by React (i.e. it no longer makescurrent
nullable). Instead,current
will only have the type you declare and be mutable.Historically
RefObject
was the type returned fromcreateRef
so it made sense to always includenull
since that what React does on initialization. The mistake we made was reusing it foruseRef
which has a different audience (useRef
for function components where it can act as "instance variables",createRef
for class components where we only care about React managed refs).But now that we moved along it makes sense to fix this incorrect abstraction, take on a breaking change and reduce papercuts going forward.
Migration
@types/*
packages to their latest versionsnpx types-react-codemod refobject-defaults ./src
(seetypes-react-codemod
for full usage)The remaining fixes should only include libraries shipping their own types. Either these libraries are already compatible with React 19 types and you just need to upgrade them or you should raise an issue on their repositories notifying them that their types are not compatible with React 19.