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] Fix some issues reported by eslint-plugin-react-compiler #43117

Merged
merged 26 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cfe6f39
prevent value mutation
binsmyth Jun 10, 2024
6602e24
Put conditionals after useRef
binsmyth Jun 14, 2024
a9171bf
disable compiler because can't prevent reassignment
binsmyth Jun 15, 2024
6262ef5
put variable change inside useEffect
binsmyth Jun 17, 2024
8eafa61
add other as dependency to useEffect
binsmyth Jun 17, 2024
04ee7d4
amend previous changes because test not passing
binsmyth Jul 26, 2024
a74e61a
add lines to disable compiler
binsmyth Jul 26, 2024
6b8b6f0
add line to disable react compiler for lines
binsmyth Jul 27, 2024
78230f5
add line to disable compiler
binsmyth Jul 30, 2024
6c90373
fixed prettier errors
binsmyth Aug 1, 2024
f8338aa
Update packages/mui-material/src/Hidden/withWidth.js
binsmyth Aug 11, 2024
a78f175
Update packages/mui-material/src/InputBase/InputBase.js
binsmyth Aug 11, 2024
4850d61
Update packages/mui-material/src/InputBase/InputBase.test.js
binsmyth Aug 11, 2024
4aa3c76
Update packages/mui-material/src/InputBase/InputBase.js
binsmyth Aug 11, 2024
b4ea6ff
Update packages/mui-material/src/InputBase/InputBase.test.js
binsmyth Aug 11, 2024
ccbc732
Update packages/mui-material/src/Select/SelectInput.js
binsmyth Aug 11, 2024
43b9fd2
Update packages/mui-material/src/SwipeableDrawer/SwipeableDrawer.js
binsmyth Aug 11, 2024
c885501
Update packages/mui-material/src/Tooltip/Tooltip.js
binsmyth Aug 11, 2024
ba82d4a
Update packages/mui-material/src/Tooltip/Tooltip.js
binsmyth Aug 11, 2024
c82e138
Update packages/mui-material/src/Tooltip/Tooltip.js
binsmyth Aug 11, 2024
b66cc4a
Update packages/mui-material/src/useScrollTrigger/useScrollTrigger.js
binsmyth Aug 11, 2024
83c46d9
Update packages/mui-material/src/styles/useTheme.js
binsmyth Aug 11, 2024
fa715b9
Update packages/mui-material/src/Snackbar/Snackbar.test.js
binsmyth Aug 11, 2024
082da68
Update packages/mui-material/src/Popover/Popover.js
binsmyth Aug 11, 2024
6b11060
Update packages/mui-material/src/Select/SelectInput.js
binsmyth Aug 11, 2024
cd0f9fa
Revert "put variable change inside useEffect"
binsmyth Aug 11, 2024
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
10 changes: 7 additions & 3 deletions packages/mui-material/src/Backdrop/Backdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import useSlot from '../utils/useSlot';
import Fade from '../Fade';
import { getBackdropUtilityClass } from './backdropClasses';

const removeOwnerState = (props) => {
const { ownerState, ...rest } = props;
return rest;
};

const useUtilityClasses = (ownerState) => {
const { classes, invisible } = ownerState;

Expand Down Expand Up @@ -96,11 +101,10 @@ const Backdrop = React.forwardRef(function Backdrop(inProps, ref) {
externalForwardedProps,
ownerState,
});

delete transitionProps.ownerState;
const transitionPropsRemoved = removeOwnerState(transitionProps);

return (
<TransitionSlot in={open} timeout={transitionDuration} {...other} {...transitionProps}>
<TransitionSlot in={open} timeout={transitionDuration} {...other} {...transitionPropsRemoved}>
<RootSlot aria-hidden {...rootProps} classes={classes} ref={ref}>
{children}
</RootSlot>
Expand Down
3 changes: 1 addition & 2 deletions packages/mui-material/src/FormControl/FormControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,8 @@ const FormControl = React.forwardRef(function FormControl(inProps, ref) {
const focused = visuallyFocused !== undefined && !disabled ? visuallyFocused : focusedState;

let registerEffect;
const registeredInput = React.useRef(false);
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line react-hooks/rules-of-hooks
const registeredInput = React.useRef(false);
registerEffect = () => {
if (registeredInput.current) {
console.error(
Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/Hidden/withWidth.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const withWidth =
*/
const keys = theme.breakpoints.keys.slice().reverse();
const widthComputed = keys.reduce((output, key) => {
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/rules-of-hooks
const matches = useMediaQuery(theme.breakpoints.up(key));
return !output && matches ? key : output;
Expand Down
2 changes: 2 additions & 0 deletions packages/mui-material/src/InputBase/InputBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ const InputBase = React.forwardRef(function InputBase(inProps, ref) {
const muiFormControl = useFormControl();

if (process.env.NODE_ENV !== 'production') {
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/rules-of-hooks
React.useEffect(() => {
if (muiFormControl) {
Expand Down Expand Up @@ -450,6 +451,7 @@ const InputBase = React.forwardRef(function InputBase(inProps, ref) {
// or auto filled by the browser before the hydration (for SSR).
React.useEffect(() => {
checkDirty(inputRef.current);
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/InputBase/InputBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ describe('<InputBase />', () => {
it('should inject onBlur and onFocus', () => {
let injectedProps;
const MyInputBase = React.forwardRef(function MyInputBase(props, ref) {
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
injectedProps = props;
return <input ref={ref} {...props} />;
});

render(<InputBase inputComponent={MyInputBase} />);
expect(typeof injectedProps.onBlur).to.equal('function');
expect(typeof injectedProps.onFocus).to.equal('function');
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Popover/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ const Popover = React.forwardRef(function Popover(inProps, ref) {
const positioning = getPositioningStyle(element);

if (positioning.top !== null) {
element.style.top = positioning.top;
element.style.setProperty('top', positioning.top);
}
if (positioning.left !== null) {
element.style.left = positioning.left;
Expand Down
2 changes: 2 additions & 0 deletions packages/mui-material/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
setMenuMinWidthState(autoWidth ? null : anchorElement.clientWidth);
displayRef.current.focus();
}
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [displayNode, autoWidth]);
// `isOpenControlled` is ignored because the component should never switch between controlled and uncontrolled modes.
Expand Down Expand Up @@ -415,6 +416,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
});

if (process.env.NODE_ENV !== 'production') {
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/rules-of-hooks
React.useEffect(() => {
if (!foundMatch && !multiple && value !== '') {
Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/Snackbar/Snackbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('<Snackbar />', () => {
let setSnackbarOpen;
function Test() {
const [open, setOpen] = React.useState(false);
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
setSnackbarOpen = setOpen;

function handleClose() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const SwipeableDrawer = React.forwardRef(function SwipeableDrawer(inProps, ref)
if (!touchDetected.current) {
return;
}
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler -- claimedSwipeInstance is a singleton
claimedSwipeInstance = null;
touchDetected.current = false;
ReactDOM.flushSync(() => {
Expand Down
9 changes: 6 additions & 3 deletions packages/mui-material/src/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,12 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) {
let open = openState;

if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line react-hooks/rules-of-hooks
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/rules-of-hooks -- process.env never changes
const { current: isControlled } = React.useRef(openProp !== undefined);

// eslint-disable-next-line react-hooks/rules-of-hooks
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/rules-of-hooks -- process.env never changes
React.useEffect(() => {
if (
childNode &&
Expand Down Expand Up @@ -599,7 +601,8 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) {
if (process.env.NODE_ENV !== 'production') {
childrenProps['data-mui-internal-clone-element'] = true;

// eslint-disable-next-line react-hooks/rules-of-hooks
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/rules-of-hooks -- process.env never changes
React.useEffect(() => {
if (childNode && !childNode.getAttribute('data-mui-internal-clone-element')) {
console.error(
Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/styles/useTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function useTheme() {
const theme = useThemeSystem(defaultTheme);

if (process.env.NODE_ENV !== 'production') {
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/rules-of-hooks
React.useDebugValue(theme);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default function useScrollTrigger(options = {}) {
const { getTrigger = defaultTrigger, target = defaultTarget, ...other } = options;
const store = React.useRef();
const [trigger, setTrigger] = React.useState(() => getTrigger(store, other));

React.useEffect(() => {
const handleScroll = () => {
setTrigger(getTrigger(store, { target, ...other }));
Expand All @@ -37,6 +36,7 @@ export default function useScrollTrigger(options = {}) {
target.removeEventListener('scroll', handleScroll, { passive: true });
};
// See Option 3. https://github.com/facebook/react/issues/14476#issuecomment-471199055
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [target, getTrigger, JSON.stringify(other)]);

Expand Down