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

Slide recreates style object property #19458

Open
2 tasks done
marlowww opened this issue Jan 28, 2020 · 0 comments
Open
2 tasks done

Slide recreates style object property #19458

marlowww opened this issue Jan 28, 2020 · 0 comments
Labels
component: transitions This is the name of the generic UI component, not the React module!

Comments

@marlowww
Copy link

marlowww commented Jan 28, 2020

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior

Slide component always recreates children style object and sets its visibility field to 'hidden' / undefined.
In such situation we cannot use neither React.memo (without compare function) nor React.PureComponent, cause function shallowEquals always returns false.

https://github.com/mui-org/material-ui/blob/5c84559ce012e403d01773112774de56d7e74723/packages/material-ui/src/Slide/Slide.js#L212-L222

Expected Behavior

Slide should try to use original style objects whenever it can.

Something like that, should be enough:

// Trying to get children style without recreating style object
const getChildrenStyle = (state) => {
  const forwardedStyle = (() => {
    if (!style) {
      return children.props.style;
    }
    if (!children.props.style) {
      return style;
    }
    return {...style, ...children.props.style};
  })();

  if (state === 'exited' && !inProp) {
    return {visibility: "hidden", ...forwardedStyle}
  }
  return forwardedStyle;
};

Steps to Reproduce

https://codesandbox.io/s/serene-easley-ll4ut

Your Environment

Tech Version
Material-UI v4.9.0
React latest
Browser chrome
@marlowww marlowww changed the title Slide component recreates style object property Slide recreates style object property Jan 29, 2020
@oliviertassinari oliviertassinari added component: transitions This is the name of the generic UI component, not the React module! and removed component: Slide labels Mar 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: transitions This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

2 participants