-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Don't construct ModalManager while document.body may still be null #4982
Don't construct ModalManager while document.body may still be null #4982
Conversation
this isn't semantically correct; we need the modal manager to be shared |
@taion Could you please elaborate? What do you mean by shared? And what isn't semantically correct? Thanks for your feedback! |
By default, all instances should use the same modal manager. Essentially, you need logic like https://github.com/react-bootstrap/react-overlays/blob/e022e9c2b66fb7a0f8ef0c172a1b12c986dbcc75/src/Modal.js#L316-L326 to make sure this happens. |
I see you point. We could also do it like that, as long as it's only going to instantiate the I'll update the PR accordingly. |
30e5541
to
5372504
Compare
PR is updated, please have another look. Thanks 👍 |
src/Modal.js
Outdated
modalContext = { | ||
onHide: () => this.props.onHide(), | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
manager = manager || props.manager || new BootstrapModalManager(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to bind the global manager to the newly constructed manager, as in the R-O code, so that additional modals use the same manager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe, since the assignment refers to the global variable, this should work as expected.
However, I updated the PR to fit the style of R-O.
please just take a look at the logic in react-overlays and use that here. that logic does the right thing. |
5372504
to
87b89aa
Compare
thanks! |
Hello everyone,
This PR is referring to the following issue #3645 which is not yet fixed.
If
ModalManager
is constructed withdefaultProps
there is still a chance thatdocument.body
is not yet present.By delaying the construction until the constructor of the
Modal
is actually called, we can avoid this problem.I know that one can avoid this problem by moving all JS includes to the body, but that can be impractical and weird in larger project, where you gotta keep track of all the includes that are being loaded.
Best,
Jo