Skip to content
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

[core] Extend StrictMode compatiblity #16283

Merged
merged 5 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/material-ui-lab/src/SpeedDial/SpeedDial.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('<SpeedDial />', () => {
}

before(() => {
// StrictModeViolation: uses ButtonBase
// StrictModeViolation: uses #simulate
mount = createMount({ strict: false });
classes = getClasses(
<SpeedDial {...defaultProps} icon={icon}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('<SpeedDialAction />', () => {
};

before(() => {
// StrictModeViolation: uses ButtonBase
// StrictModeViolation: uses #simulate
mount = createMount({ strict: false });
classes = getClasses(<SpeedDialAction {...defaultProps} />);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('<ToggleButton />', () => {
let classes;

before(() => {
// StrictModeViolation: uses ButtonBase
// StrictModeViolation: uses #simulate
mount = createMount({ strict: false });
render = createRender();
classes = getClasses(<ToggleButton value="classes">Hello World</ToggleButton>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ describe('<ToggleButtonGroup />', () => {
let classes;

before(() => {
// StrictModeViolation: uses ButtonBase
mount = createMount({ strict: false });
mount = createMount({ strict: true });
classes = getClasses(
<ToggleButtonGroup>
<ToggleButton value="hello" />
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"dependencies": {
"@babel/runtime": "^7.2.0",
"@material-ui/react-transition-group": "^4.2.0",
"@material-ui/styles": "^4.1.1",
"@material-ui/system": "^4.2.0",
"@material-ui/types": "^4.1.0",
Expand All @@ -53,7 +54,6 @@
"popper.js": "^1.14.1",
"prop-types": "^15.7.2",
"react-event-listener": "^0.6.6",
"react-transition-group": "^4.0.0",
"warning": "^4.0.1"
},
"sideEffects": false,
Expand Down
14 changes: 2 additions & 12 deletions packages/material-ui/src/Backdrop/Backdrop.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import React from 'react';
import { assert } from 'chai';
import { createMount, createShallow, getClasses } from '@material-ui/core/test-utils';
import { createMount, getClasses } from '@material-ui/core/test-utils';
import describeConformance from '../test-utils/describeConformance';
import Backdrop from './Backdrop';

describe('<Backdrop />', () => {
let mount;
let shallow;
let classes;

before(() => {
// StrictModeViolation: uses Fade
mount = createMount({ strict: false });
shallow = createShallow({ dive: true });
mount = createMount({ strict: true });
classes = getClasses(<Backdrop open />);
});

Expand All @@ -27,10 +23,4 @@ describe('<Backdrop />', () => {
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
}));

it('should render a backdrop div', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already tested in describeConformance

const wrapper = shallow(<Backdrop open className="woofBackdrop" />);
assert.strictEqual(wrapper.childAt(0).hasClass('woofBackdrop'), true);
assert.strictEqual(wrapper.childAt(0).hasClass(classes.root), true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ describe('<BottomNavigation />', () => {
<BottomNavigationAction icon={icon} />
</BottomNavigation>,
);
// StrictModeViolation: uses BottomNavigationAction
mount = createMount({ strict: false });
mount = createMount({ strict: true });
});

after(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('<BottomNavigationAction />', () => {
const icon = <Icon>restore</Icon>;

before(() => {
// StrictModeViolation: uses ButtonBase
// StrictModeViolation: uses #StrictMode
mount = createMount({ strict: false });
classes = getClasses(<BottomNavigationAction />);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/ButtonBase/ButtonBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('<ButtonBase />', () => {

before(() => {
shallow = createShallow({ dive: true, disableLifecycleMethods: true });
// StrictModeViolation: uses TouchRipple
// StrictModeViolation: uses simulate
mount = createMount({ strict: false });
classes = getClasses(<ButtonBase />);
});
Expand Down
13 changes: 10 additions & 3 deletions packages/material-ui/src/ButtonBase/Ripple.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { Transition } from 'react-transition-group';
import { Transition } from '@material-ui/react-transition-group';

/**
* @ignore - internal component.
Expand Down Expand Up @@ -40,9 +40,16 @@ function Ripple(props) {
[classes.childPulsate]: pulsate,
});

const rippleRef = React.useRef();

return (
<Transition onEnter={handleEnter} onExit={handleExit} {...other}>
<span className={rippleClassName} style={rippleStyles}>
<Transition
onEnter={handleEnter}
onExit={handleExit}
{...other}
findDOMNode={() => rippleRef.current}
>
<span className={rippleClassName} ref={rippleRef} style={rippleStyles}>
<span className={childClassName} />
</span>
</Transition>
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/ButtonBase/TouchRipple.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { TransitionGroup } from 'react-transition-group';
import { TransitionGroup } from '@material-ui/react-transition-group';
import clsx from 'clsx';
import withStyles from '../styles/withStyles';
import Ripple from './Ripple';
Expand Down
3 changes: 1 addition & 2 deletions packages/material-ui/src/Checkbox/Checkbox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ describe('<Checkbox />', () => {

before(() => {
classes = getClasses(<Checkbox />);
// StrictModeViolation: uses IconButton
mount = createMount({ strict: false });
mount = createMount({ strict: true });
});

after(() => {
Expand Down
9 changes: 7 additions & 2 deletions packages/material-ui/src/Collapse/Collapse.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import { Transition } from 'react-transition-group';
import { Transition } from '@material-ui/react-transition-group';
import withStyles from '../styles/withStyles';
import { duration } from '../styles/transitions';
import { getTransitionProps } from '../transitions/utils';
import { useForkRef } from '../utils/reactHelpers';

export const styles = theme => ({
/* Styles applied to the container element. */
Expand Down Expand Up @@ -149,6 +150,9 @@ const Collapse = React.forwardRef(function Collapse(props, ref) {
}
};

const ownRef = React.useRef();
const handleRef = useForkRef(ownRef, ref);

return (
<Transition
in={inProp}
Expand All @@ -160,6 +164,7 @@ const Collapse = React.forwardRef(function Collapse(props, ref) {
addEndListener={addEndListener}
timeout={timeout === 'auto' ? null : timeout}
{...other}
findDOMNode={() => ownRef.current}
>
{(state, childProps) => (
<Component
Expand All @@ -175,7 +180,7 @@ const Collapse = React.forwardRef(function Collapse(props, ref) {
minHeight: collapsedHeight,
...style,
}}
ref={ref}
ref={handleRef}
{...childProps}
>
<div className={classes.wrapper} ref={wrapperRef}>
Expand Down
5 changes: 2 additions & 3 deletions packages/material-ui/src/Collapse/Collapse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createMount, getClasses } from '@material-ui/core/test-utils';
import describeConformance from '../test-utils/describeConformance';
import Collapse from './Collapse';
import { createMuiTheme } from '@material-ui/core/styles';
import { Transition } from 'react-transition-group';
import { Transition } from '@material-ui/react-transition-group';

describe('<Collapse />', () => {
let mount;
Expand All @@ -16,8 +16,7 @@ describe('<Collapse />', () => {
};

before(() => {
// StrictModeViolation: uses react-transition-group
mount = createMount({ strict: false });
mount = createMount({ strict: true });
classes = getClasses(<Collapse {...defaultProps} />);
});

Expand Down
3 changes: 1 addition & 2 deletions packages/material-ui/src/Dialog/Dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ describe('<Dialog />', () => {
};

before(() => {
// StrictModeViolation: uses Fade
mount = createMount({ strict: false });
mount = createMount({ strict: true });
classes = getClasses(<Dialog {...defaultProps}>foo</Dialog>);
});

Expand Down
3 changes: 1 addition & 2 deletions packages/material-ui/src/Drawer/Drawer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ describe('<Drawer />', () => {
let classes;

before(() => {
// StrictModeViolation: uses Slide
mount = createMount({ strict: false });
mount = createMount({ strict: true });
classes = getClasses(
<Drawer>
<div />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ describe('<ExpansionPanel />', () => {
const minimalChildren = [<ExpansionPanelSummary key="header" />];

before(() => {
// StrictModeViolation: uses Collapse
mount = createMount({ strict: false });
mount = createMount({ strict: true });
classes = getClasses(<ExpansionPanel>{minimalChildren}</ExpansionPanel>);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('<ExpansionPanelSummary />', () => {
}

before(() => {
// StrictModeViolation: uses ButtonBase
// StrictModeViolation: uses #simulate
mount = createMount({ strict: false });
classes = getClasses(<ExpansionPanelSummary />);
});
Expand Down
8 changes: 6 additions & 2 deletions packages/material-ui/src/Fade/Fade.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Transition } from 'react-transition-group';
import { Transition } from '@material-ui/react-transition-group';
import { duration } from '../styles/transitions';
import withTheme from '../styles/withTheme';
import { reflow, getTransitionProps } from '../transitions/utils';
Expand Down Expand Up @@ -35,7 +35,6 @@ const Fade = React.forwardRef(function Fade(props, ref) {
timeout = defaultTimeout,
...other
} = props;
const handleRef = useForkRef(children.ref, ref);

const handleEnter = node => {
reflow(node); // So the animation always start from the start.
Expand Down Expand Up @@ -69,6 +68,10 @@ const Fade = React.forwardRef(function Fade(props, ref) {
}
};

const ownRef = React.useRef();
const userRef = useForkRef(children.ref, ref);
const handleRef = useForkRef(ownRef, userRef);

return (
<Transition
appear
Expand All @@ -77,6 +80,7 @@ const Fade = React.forwardRef(function Fade(props, ref) {
onExit={handleExit}
timeout={timeout}
{...other}
findDOMNode={() => ownRef.current}
>
{(state, childProps) => {
return React.cloneElement(children, {
Expand Down
5 changes: 2 additions & 3 deletions packages/material-ui/src/Fade/Fade.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { spy, useFakeTimers } from 'sinon';
import { createMount } from '@material-ui/core/test-utils';
import describeConformance from '@material-ui/core/test-utils/describeConformance';
import Fade from './Fade';
import { Transition } from 'react-transition-group';
import { Transition } from '@material-ui/react-transition-group';

describe('<Fade />', () => {
let mount;
Expand All @@ -15,8 +15,7 @@ describe('<Fade />', () => {
};

before(() => {
// StrictModeViolation: uses react-transition-group
mount = createMount({ strict: false });
mount = createMount({ strict: true });
});

after(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ describe('<FormControlLabel />', () => {
let classes;

before(() => {
// StrictModeViolation: uses Checkbox in test
mount = createMount({ strict: false });
mount = createMount({ strict: true });
classes = getClasses(<FormControlLabel label="Pizza" control={<div />} />);
});

Expand Down
8 changes: 6 additions & 2 deletions packages/material-ui/src/Grow/Grow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Transition } from 'react-transition-group';
import { Transition } from '@material-ui/react-transition-group';
import withTheme from '../styles/withTheme';
import { reflow, getTransitionProps } from '../transitions/utils';
import { useForkRef } from '../utils/reactHelpers';
Expand Down Expand Up @@ -30,7 +30,6 @@ const Grow = React.forwardRef(function Grow(props, ref) {
const { children, in: inProp, onEnter, onExit, style, theme, timeout = 'auto', ...other } = props;
const timer = React.useRef();
const autoTimeout = React.useRef();
const handleRef = useForkRef(children.ref, ref);

const handleEnter = node => {
reflow(node); // So the animation always start from the start.
Expand Down Expand Up @@ -112,6 +111,10 @@ const Grow = React.forwardRef(function Grow(props, ref) {
};
}, []);

const ownRef = React.useRef();
const userRef = useForkRef(children.ref, ref);
const handleRef = useForkRef(userRef, ownRef);

return (
<Transition
appear
Expand All @@ -121,6 +124,7 @@ const Grow = React.forwardRef(function Grow(props, ref) {
addEndListener={addEndListener}
timeout={timeout === 'auto' ? null : timeout}
{...other}
findDOMNode={() => ownRef.current}
>
{(state, childProps) => {
return React.cloneElement(children, {
Expand Down
5 changes: 2 additions & 3 deletions packages/material-ui/src/Grow/Grow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createMount } from '@material-ui/core/test-utils';
import describeConformance from '@material-ui/core/test-utils/describeConformance';
import Grow from './Grow';
import { createMuiTheme } from '@material-ui/core/styles';
import { Transition } from 'react-transition-group';
import { Transition } from '@material-ui/react-transition-group';

describe('<Grow />', () => {
let mount;
Expand All @@ -15,8 +15,7 @@ describe('<Grow />', () => {
};

before(() => {
// StrictModeViolation: uses react-transition-group
mount = createMount({ strict: false });
mount = createMount({ strict: true });
});

after(() => {
Expand Down
3 changes: 1 addition & 2 deletions packages/material-ui/src/IconButton/IconButton.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ describe('<IconButton />', () => {

before(() => {
shallow = createShallow({ dive: true });
// StrictModeViolation: uses ButtonBase
mount = createMount({ strict: false });
mount = createMount({ strict: true });
classes = getClasses(<IconButton />);
});

Expand Down
3 changes: 1 addition & 2 deletions packages/material-ui/src/ListItem/ListItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ describe('<ListItem />', () => {

before(() => {
classes = getClasses(<ListItem />);
// StrictModeViolation: uses ButtonBase
mount = createMount({ strict: false });
mount = createMount({ strict: true });
});

after(() => {
Expand Down