diff --git a/src/CSSMotion.tsx b/src/CSSMotion.tsx index 5660e20..182ac34 100644 --- a/src/CSSMotion.tsx +++ b/src/CSSMotion.tsx @@ -1,6 +1,6 @@ /* eslint-disable react/default-props-match-prop-types, react/no-multi-comp, react/prop-types */ import classNames from 'classnames'; -import findDOMNode from 'rc-util/lib/Dom/findDOMNode'; +import { getDOM } from 'rc-util/lib/Dom/findDOMNode'; import { fillRef, getNodeRef, supportRef } from 'rc-util/lib/ref'; import * as React from 'react'; import { useRef } from 'react'; @@ -142,13 +142,9 @@ export function genCSSMotion(config: CSSMotionConfig) { function getDomElement() { try { - // Here we're avoiding call for findDOMNode since it's deprecated - // in strict mode. We're calling it only when node ref is not - // an instance of DOM HTMLElement. Otherwise use - // findDOMNode as a final resort return nodeRef.current instanceof HTMLElement ? nodeRef.current - : findDOMNode(wrapperNodeRef.current); + : (getDOM(nodeRef.current) as HTMLElement); } catch (e) { // Only happen when `motionDeadline` trigger but element removed. return null; diff --git a/tests/CSSMotion.spec.tsx b/tests/CSSMotion.spec.tsx index b5c71a9..b947369 100644 --- a/tests/CSSMotion.spec.tsx +++ b/tests/CSSMotion.spec.tsx @@ -5,7 +5,6 @@ import { act, fireEvent, render } from '@testing-library/react'; import classNames from 'classnames'; import React from 'react'; -import ReactDOM from 'react-dom'; import type { CSSMotionProps } from '../src'; import { Provider } from '../src'; import RefCSSMotion, { genCSSMotion } from '../src/CSSMotion'; @@ -830,78 +829,6 @@ describe('CSSMotion', () => { expect(container.querySelector('.motion-box')).toHaveClass('removed'); }); - describe('strict mode', () => { - beforeEach(() => { - jest.spyOn(ReactDOM, 'findDOMNode'); - }); - - afterEach(() => { - jest.resetAllMocks(); - }); - - it('calls findDOMNode when no refs are passed', () => { - const Div = () =>
; - render( - - {() =>
} - , - ); - - act(() => { - jest.runAllTimers(); - }); - - expect(ReactDOM.findDOMNode).toHaveBeenCalled(); - }); - - it('does not call findDOMNode when ref is passed internally', () => { - render( - - {(props, ref) =>
} - , - ); - - act(() => { - jest.runAllTimers(); - }); - - expect(ReactDOM.findDOMNode).not.toHaveBeenCalled(); - }); - - it('calls findDOMNode when refs are forwarded but not assigned', () => { - const domRef = React.createRef(); - const Div = () =>
; - - render( - - {() =>
} - , - ); - - act(() => { - jest.runAllTimers(); - }); - - expect(ReactDOM.findDOMNode).toHaveBeenCalled(); - }); - - it('does not call findDOMNode when refs are forwarded and assigned', () => { - const domRef = React.createRef(); - - render( - - {(props, ref) =>
} - , - ); - - act(() => { - jest.runAllTimers(); - }); - - expect(ReactDOM.findDOMNode).not.toHaveBeenCalled(); - }); - }); - describe('onVisibleChanged', () => { it('visible', () => { const onVisibleChanged = jest.fn();