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-open class is not being added to body in some cases #1279

Closed
python273 opened this issue Oct 28, 2018 · 5 comments
Closed

modal-open class is not being added to body in some cases #1279

python273 opened this issue Oct 28, 2018 · 5 comments

Comments

@python273
Copy link

  • components: Modal
  • reactstrap version #6.5.0
  • import method umd/csj/es
  • react version #16.4.1
  • bootstrap version #4.1.3

What is happening?

Modal.destroy might be called twice on close + unmount, so Modal.openCount is becoming negative and modal-open is not being added to body

What should be happening?

Modal.destroy should not be called twice on close + unmount

Steps to reproduce issue

  1. Open https://stackblitz.com/edit/reactstrap-hgyxbh?file=Example.js
  2. Press "Edit something"
    modal-open is added to body
  3. Close modal
  4. Open modal
    modal-open is not added to body
@chriswayoub
Copy link

I ran into this same issue. I was conditionally rendering the Modal component, and I was hiding it in the onClose callback. This caused it to call componentWillUnmount() to be called immediately after the Modal.onClosed() method before the state.isOpen update had propagated. So destroy() ended up being called again in componentWillUnmount() after it had already been called in onClose().

I ended up just waiting to unmount the component until the next update cycle. If this is considered a bug, then it's probably best to use something other than the state to track whether or not the modal needs to be destroyed so you don't have to worry about any state race conditions.

@x0a x0a mentioned this issue Jan 18, 2019
12 tasks
@epcliff
Copy link

epcliff commented Jul 31, 2019

Is there fix to this issue? I'm having the same problem.

@python273
Copy link
Author

There's a hacky solution. You need to wait until a modal is closed and only then unmount it

Fixed example: https://stackblitz.com/edit/reactstrap-jynqel?file=Example.js

@python273
Copy link
Author

Though if you have only one opened modal, it should work ok I think (#1368)

@GoPro16
Copy link
Member

GoPro16 commented Feb 26, 2020

I think the latter issue here is the Modal component is already driving whether or not to show or hide the contents. Mounting and unmounting the modal component and also controlling the modal open state inside another component seems redundant.

This could be why there are no other reported cases of this.

Furthermore, I was checking out the stackblitz link and it looks to me like the modal-body is being appended properly to the tag. Please re-open and include an updated stackblitz if this issue is still persisting for you.

@GoPro16 GoPro16 closed this as completed Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants