Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
d2ac096 to
4cbcf5f
Compare
|
Size Change: +32 B (0%) Total Size: 3.03 MB
ℹ️ View Unchanged
|
aduth
left a comment
There was a problem hiding this comment.
There seem to be a number of instances remaining after the changes here in .js files, do those need to be updated as well?
e.g.
gutenberg/packages/block-editor/src/components/link-control/index.js
Lines 228 to 230 in 4cbcf5f
(plus many more)
| */ | ||
| function useHandleOnload( containerRef: React.RefObject< HTMLDivElement > ) { | ||
| function useHandleOnload( | ||
| containerRef: React.RefObject< HTMLDivElement | null > |
There was a problem hiding this comment.
containerRef is a ref created with useRef:
const containerRef = useRef<HtmlDivElement>(null)and this call returns a RefObject<HtmlDivElement|null>. It's an object whose .current field can be null and the ref is passed to a div as <div ref={containerRef}>. React is really going to assign null values there.
That's why useHandleOnload needs to have compatible types. This is something you'll see after upgrading to React 19 which has bugfixed ref types. Typechecking with React 18 doesn't detect this. But the change is compatible.
Thanks for noticing this. These files are not typechecked, usually because given package's |
aduth
left a comment
There was a problem hiding this comment.
Thanks for clarifying those points. LGTM 👍
Spinoff from React 19 migration (#61521) which fixes many calls to
useRef.First of all, React 19 types require that
useRefis always called with one argument, the initial value. Passing zero arguments is no longer an option, even when it'sundefined.Second, we need to carefully distinguish between:
useRef<T>(null)which returns a ref that is not mutable, intended to be passed to a component. Like<div ref={ref}>. You can't manually assign.current.useRef<T>(undefined)which returns a mutable ref that is iniitally not set. You can assign.currentmanually.useRef<T | null>(null)which can be used to create a mutable ref withnullinitial value. Without the| nullsuffix in the type the ref wouldn't be mutable.This PR improves compatibility with React 19 types while still using React 18. In React 19 there will be additional change: the
MutableRefObjectis deprecated and no longer used, and all refs are mutable. The subtle distinctions betweennullandundefineddescribed above won't be relevant any more.