Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/CSSMotion.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<HTMLElement>(wrapperNodeRef.current);
: (getDOM(nodeRef.current) as HTMLElement);
} catch (e) {
// Only happen when `motionDeadline` trigger but element removed.
return null;
Expand Down
73 changes: 0 additions & 73 deletions tests/CSSMotion.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = () => <div />;
render(
<CSSMotion motionName="transition" visible>
{() => <Div />}
</CSSMotion>,
);

act(() => {
jest.runAllTimers();
});

expect(ReactDOM.findDOMNode).toHaveBeenCalled();
});

it('does not call findDOMNode when ref is passed internally', () => {
render(
<CSSMotion motionName="transition" visible>
{(props, ref) => <div ref={ref} />}
</CSSMotion>,
);

act(() => {
jest.runAllTimers();
});

expect(ReactDOM.findDOMNode).not.toHaveBeenCalled();
});

it('calls findDOMNode when refs are forwarded but not assigned', () => {
const domRef = React.createRef();
const Div = () => <div />;

render(
<CSSMotion motionName="transition" visible ref={domRef}>
{() => <Div />}
</CSSMotion>,
);

act(() => {
jest.runAllTimers();
});

expect(ReactDOM.findDOMNode).toHaveBeenCalled();
});

it('does not call findDOMNode when refs are forwarded and assigned', () => {
const domRef = React.createRef();

render(
<CSSMotion motionName="transition" visible ref={domRef}>
{(props, ref) => <div ref={ref} />}
</CSSMotion>,
);

act(() => {
jest.runAllTimers();
});

expect(ReactDOM.findDOMNode).not.toHaveBeenCalled();
});
});

describe('onVisibleChanged', () => {
it('visible', () => {
const onVisibleChanged = jest.fn();
Expand Down
Loading