You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
React 19 has removed the ReactDOM.findDOMNode method. #918
Reacted by Toru Kobayashi, Tomasz Szewczyk, Julio Lozovei, Vladyslav Shlianin, Peter Hubner, Lonca Sorin, mabasic, Jasmin Fitz, Вячеслав Дьяченко, Malloy and 13 more
Reacted by Tore Sinding Bekkedal, Jinho and Akshay Ashok
@sergioviniciuss yes it still works exactly how it did before. Make sure that the ref is set to the correct element, if you inspect the value, nodeRef.current should be the element that you want the classes applied to.
Passing this reference around may not be what you want to do, especially if you have an animate wrapper component like my codebase does. The solution I was able to find with my colleague was to use a context:
// AnimateMyComponent.jsximport{Children,useRef,createContext}from"react";import{CSSTransition}from"react-transition-group";functionAnimateMyComponent({ children }){constcomponent=Children.only(children);constnodeRef=useRef(null);return(<CSSTransitionnodeRef={nodeRef}{...otherProps}><AnimationContext.Providervalue={nodeRef}>{component}</AnimationContext.Provider></CSSTransition>);};exportdefaultAnimateMyComponent;exportconstAnimationContext=createContext(null);// MyComponent.jsximportAnimateMyComponentfrom"./AnimateMyComponent";importMyFunctionalComponentfrom"./MyFunctionalComponent";importMyClassComponentfrom"./MyClassComponent";functionMyComponent({ myBoolean }){return(<div><AnimateMyComponent>{myBoolean ? (<MyFunctionalComponent/>) : (<MyClassComponent/>)}</AnimateMyComponent></div>);};exportdefaultMyComponent;// MyFunctionalComponent.jsximport{useContext}from"react";import{AnimationContext}from"./AnimateMyComponent";functionMyFunctionalComponent(){constanimationRef=useContext(AnimationContext);return(<divref={animationRef}>...</div>);};exportdefaultMyFunctionalComponent;// what type AnimationContext would be in a typescript .tsx functional componentconstanimationRef=useContext(AnimationContextasReact.Context<React.RefObject<HTMLElement>>);// MyClassComponent.jsximport{AnimationContext}from"./AnimateMyComponent";exportdefaultclassMyClassComponentextendsReact.Component{render(){return(<AnimationContext.Consumer>{(animationRef)=>(<divref={animationRef}>...</div>)}</AnimationContext.Consumer>);}};
I hope this is helpful to all and also to you specifically, @sergioviniciuss :D
Another option is to create a wrapper component that handles creating and passing nodeRef internally. The only issue with this is that it will wrap all of your transitions in a <div> (or whatever HTML element you use here). This could break styling or other things if your code isn't expecting these elements to be wrapped.
importReactfrom"react";importCSSTransition,{CSSTransitionProps}from"react-transition-group/CSSTransition";exportfunctionCSSTransitionWrapped(props: React.PropsWithChildren<CSSTransitionProps>){constnodeRef=React.useRef<HTMLElement>(null);const{ children, ...propsRest}=props;functionsetRef(value: HTMLDivElement|null){// Set the nodeRef to the first child of the div, emulating findDOMNode behaviornodeRef.current=value?.firstElementChildasHTMLElement;}return(<CSSTransitionnodeRef={nodeRef}{...propsRest}><divref={setRef}>{children}</div></CSSTransition>);}
Then use it exactly like CSSTransition was used before, it will work with HTML children or react component children:
Here the <div> will get transition classes applied to it:
Another option is to create a wrapper component that handles creating and passing nodeRef internally. The only issue with this is that it will wrap all of your transitions in a <div> (or whatever HTML element you use here). This could break styling or other things if your code isn't expecting these elements to be wrapped.
import React from "react";
import CSSTransition, { CSSTransitionProps } from "react-transition-group/CSSTransition";
function setRef(value: HTMLDivElement | null) {
// Set the nodeRef to the first child of the div, emulating findDOMNode behavior
nodeRef.current = value?.firstElementChild as HTMLElement;
}
);
}
Then use it exactly like CSSTransition was used before, it will work with HTML children or react component children:
Here the <div> will get transition classes applied to it:
<CSSTransitionWrapped {...transitionProps}>
...
And here the root element of `SomeComponent` will get the transition classes applied to it:
<CSSTransitionWrapped {...transitionProps}>
This works without unintended styling issues if you add style={{ display: 'contents' }} to the wrapping div. It will basically make the div not exist for the purposes of layout, but still works to mimic the findDOMNode behavior
Props passed to the CSSTransitionWrapper meant to be pass-through were ending up on the wrapper div. To get them to be forwarded to the wrapped component instead:
nothing in node_modules gets patched. tested CSSTransition without nodeRef in dev and prod builds. it reads react internals (_reactInternals) under the hood, so treat it as a stopgap until libs move to refs
If adding nodeRef everywhere isn't practical (or the transition sits inside a library like react-bootstrap 1.x or Material-UI 4): I published a fork, @fitzyracing/react-transition-group@4.4.6, that works on React 19 without nodeRef. It puts its own ref on the child, combined with any ref the child already has, and reads the node from that. On React 16.6–18 it still calls findDOMNode exactly like 4.4.5. Same API and callback arguments.
To fix it inside your dependencies without changing code:
One caveat on React 19: the child has to accept a ref (a DOM element, a forwardRef component, or a function component that passes ref on). Otherwise pass nodeRef as before. Source and tests: https://github.com/fitzyracing1/react-transition-group. Happy to drop it if upstream ships a release.
If adding nodeRef isn't an option, for example because the transition is inside a library like react-bootstrap 1.x, reactstrap or react-bootstrap-table-next: I published an unofficial fork, @nerdnog/react-transition-group 4.5.0. It's 4.4.5 with the findDOMNode calls replaced, and nothing else changed.
On React 19 it finds the same element 4.4.5 did, by reading React's internal records. Children that don't pass a ref through, and render-prop children, still animate. On React 16 to 18 it still calls findDOMNode.
If it can't find the element, it warns in development and finishes the transition instead of crashing.
It needs no build step. Swap it in with one line in package.json:
Yarn uses resolutions and pnpm uses pnpm.overrides. The readme covers apps that depend on react-transition-group directly.
Tested on React 19.3.1, in dev and production builds, with react-bootstrap-table-next's expandRow, reactstrap's Carousel, and react-bootstrap 1.6's Collapse and Fade. react-bootstrap 1.6's Modal still crashes on React 19 for a separate reason: React 19 ignores its defaultProps.
React doesn't support reading its internal records, so CI runs weekly against React's canary to catch breakage early.
Activity
mogzol commentedon Jan 24, 2025
This can be worked around by ensuring you pass a
nodeRefto all of the transitions:sergioviniciuss commentedon Feb 5, 2025
@mogzol this bypasses the error, but also cuts the effect of the library... Is it still working normally for you?
In my case I use it for slidedown transitions, and I also added this fix you shared, but although error is gone, the transition effect is gone.
mogzol commentedon Feb 5, 2025
@sergioviniciuss yes it still works exactly how it did before. Make sure that the ref is set to the correct element, if you inspect the value,
nodeRef.currentshould be the element that you want the classes applied to.SBOpalG commentedon Feb 5, 2025
I have found that the above work around is functional when the top level element is an html element but not if it's a React component.
An example one that does not work:
This is fixed by adding the ref instead to the top level element that is an html element:
Passing this reference around may not be what you want to do, especially if you have an animate wrapper component like my codebase does. The solution I was able to find with my colleague was to use a context:
I hope this is helpful to all and also to you specifically, @sergioviniciuss :D
mogzol commentedon Feb 6, 2025
Another option is to create a wrapper component that handles creating and passing
nodeRefinternally. The only issue with this is that it will wrap all of your transitions in a<div>(or whatever HTML element you use here). This could break styling or other things if your code isn't expecting these elements to be wrapped.Then use it exactly like CSSTransition was used before, it will work with HTML children or react component children:
Here the
<div>will get transition classes applied to it:And here the root element of
SomeComponentwill get the transition classes applied to it:todor-a commentedon Feb 6, 2025
Stumbled upon this. Looks like a modern alternative.
nikitayutanov commentedon Feb 12, 2025
Here's the improved version of the above solution by @mogzol, without the need for an additional
divwrapper.Drawbacks:
refas a prop to their container element.refis already specified onchildren, it will be overridden.TNAJanssen commentedon Jul 4, 2025
react-transition-group+4.4.5.patch
mattrunyon commentedon Sep 15, 2025
This works without unintended styling issues if you add
style={{ display: 'contents' }}to the wrapping div. It will basically make the div not exist for the purposes of layout, but still works to mimic thefindDOMNodebehaviorwelkup commentedon Oct 13, 2025
Thanks @mogzol!
Props passed to the
CSSTransitionWrappermeant to be pass-through were ending up on the wrapper div. To get them to be forwarded to the wrapped component instead:Also, be careful if you are wrapping a component that renders using
createPortal.findDOMNodehandled this case, but thesetReffunction does not.infinitybuddha29 commentedon Oct 7, 2026
if adding nodeRef everywhere isn't an option (or the CSSTransition sits inside some other lib you can't edit), I made a small build plugin that puts findDOMNode back for react-dom 19: https://github.com/infinitybuddha29/react-legacy-compat
works with vite, webpack 5 and next 15/16, turbopack included. for next it's just
nothing in node_modules gets patched. tested CSSTransition without nodeRef in dev and prod builds. it reads react internals (_reactInternals) under the hood, so treat it as a stopgap until libs move to refs
fitzyracing1 commentedon Oct 8, 2026
If adding
nodeRefeverywhere isn't practical (or the transition sits inside a library like react-bootstrap 1.x or Material-UI 4): I published a fork, @fitzyracing/react-transition-group@4.4.6, that works on React 19 withoutnodeRef. It puts its own ref on the child, combined with any ref the child already has, and reads the node from that. On React 16.6–18 it still callsfindDOMNodeexactly like 4.4.5. Same API and callback arguments.To fix it inside your dependencies without changing code:
One caveat on React 19: the child has to accept a
ref(a DOM element, aforwardRefcomponent, or a function component that passesrefon). Otherwise passnodeRefas before. Source and tests: https://github.com/fitzyracing1/react-transition-group. Happy to drop it if upstream ships a release.mrkevbro commentedon Nov 28, 2026
If adding
nodeRefisn't an option, for example because the transition is inside a library like react-bootstrap 1.x, reactstrap or react-bootstrap-table-next: I published an unofficial fork,@nerdnog/react-transition-group4.5.0. It's 4.4.5 with thefindDOMNodecalls replaced, and nothing else changed.findDOMNode.package.json:Yarn uses
resolutionsand pnpm usespnpm.overrides. The readme covers apps that depend on react-transition-group directly.Tested on React 19.3.1, in dev and production builds, with react-bootstrap-table-next's expandRow, reactstrap's Carousel, and react-bootstrap 1.6's Collapse and Fade. react-bootstrap 1.6's Modal still crashes on React 19 for a separate reason: React 19 ignores its
defaultProps.React doesn't support reading its internal records, so CI runs weekly against React's canary to catch breakage early.
Code and issues: https://github.com/nerdnog/react-transition-group