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

Modal: on close warning in 0.75 #2236

Closed
laukaichung opened this issue Oct 22, 2017 · 3 comments
Closed

Modal: on close warning in 0.75 #2236

laukaichung opened this issue Oct 22, 2017 · 3 comments
Assignees
Labels

Comments

@laukaichung
Copy link

Steps

0.75.1 example
0.74 example

Sometimes I have to pragmatically open or close a modal without the help of trigger prop. This is just an example:

class Example extends React.Component {
  state = { open: false }
  constructor(props){
      super(props);
      this._toggle = this._toggle.bind(this);
  }
  render() {
    const { open } = this.state
    return (
      open?
      <Modal
        open={open}
        onOpen={this.open}
        onClose={this._toggle}
        size='small'>
        dgfdgfdgfdgf
      </Modal>
       : <Button onClick={this._toggle} primary>Open</Button>

    )
  }

  _toggle(){
    this.setState({open:!this.state.open})
  }
}

Before 0.75, I can do that without a warning, as shown in the 0.74 example.

Actual Result

However, since 0.75, I'm getting this warning when onClose is fired:

Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.

Is it a bug or do I really need to use a trigger element from now on?

Version

0.75.1

@layershifter layershifter changed the title Modal on close warning in 0.75 Modal: on close warning in 0.75 Oct 23, 2017
@layershifter
Copy link
Member

Looks like bug, the investigation and contributions are welcome.

@laukaichung
Copy link
Author

laukaichung commented Oct 25, 2017

@layershifter
I suspect in 0.75, the new argument {scrolling:false} for trySetState in Modal.js is causing the error in /lib/AutoControlledComponent.js

  handleClose = (e) => {
    debug('close()')

    const { onClose } = this.props
    if (onClose) onClose(e, this.props)

    this.trySetState({ open: false }, { scrolling: false })
  }

The error is thrown when trySetState in /lib/AutoControlledComponent.js is updating the new state { scrolling: false }

AutoControlledComponent.js

  this.trySetState = function (maybeState, state) {
      /...../
      if (Object.keys(newState).length > 0) _this3.setState(newState); <<
  }

@layershifter
Copy link
Member

@stonecold123 Thanks 👍 Seems, you're right. I will check this in evening and will make PR

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

No branches or pull requests

2 participants