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

Transition: hiding automatically when setState of parent called on mount #3641

Closed
krajasekhar opened this issue Jun 3, 2019 · 6 comments
Closed

Comments

@krajasekhar
Copy link

Bug Report

Steps

  1. When the child of Transition is a stateful component and is not enclosed by any div in the parent component, hide of transition is not hiding the child but the visible prop is actually false at the moment.
  2. When the child of Transition is a stateful component and enclosed by div in parent component, if any function gets triggered from child's componentDidMount which do a setState in parent, transition is hiding the child but the visible prop is still true.
    If unmountOnHide is set true, this auto hide happens after every visible trigger.

Expected Result

  1. Shall hide the child component.
  2. Shall not auto hide on open.

Actual Result

  1. Hide not happening.
  2. Auto closing after making it visible.

Version

0.87.1

Testcase

[Fork, update, and replace this pen to show the bug]:

  1. https://codesandbox.io/s/transitionhideissue-upze1
  2. https://codesandbox.io/s/transitionautocloseissue-lj3km
@layershifter
Copy link
Member

It's expected, your component should spread props, at least className and style props:

-<div {...this.props}>
+<div {...this.props}>
+ // or <div className={this.props.className} style={this.props.style}>
  <Image
    size="small"
    src="https://react.semantic-ui.com/images/leaves/1.png"
   />
</div>

This change fixes both examples.

@krajasekhar
Copy link
Author

It's expected, your component should spread props, at least className and style props:

-<div {...this.props}>
+<div {...this.props}>
+ // or <div className={this.props.className} style={this.props.style}>
  <Image
    size="small"
    src="https://react.semantic-ui.com/images/leaves/1.png"
   />
</div>

This change fixes both examples.

Hi, Thanks for helping.
This change didn't fix the 2nd example. Please check
https://codesandbox.io/s/transitionautocloseissue-lj3km

@krajasekhar
Copy link
Author

The work around fix I got for this is to call setState after the running execution by putting inside setTimeout with zero delay.
setTimeout(() => { this.setState({ name: data.value }); }, 0);

@layershifter layershifter reopened this Jun 3, 2019
@layershifter layershifter changed the title Transition hiding automatically when setState of parent called on mount of child enclosed by div, not at all hiding when child not enclosed with any div Transition: hiding automatically when setState of parent called on mount Jun 3, 2019
@layershifter
Copy link
Member

@krajasekhar thanks for the clarification, definitely looks like a bug 🐛

@honzajerabek
Copy link
Contributor

Another workaround that fixes this for me is to use React.memo() HOC in order to prevent unnecessary re-render of the child component, and trigger the unwanted hide

@layershifter
Copy link
Member

This issue was fixed in semantic-ui-react@1.0.0 (#3982) and I can't repro it anymore in linked CodeSandboxes. Please let us know if something still fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants