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

Don't construct ModalManager while document.body may still be null #4982

Conversation

xijo
Copy link
Contributor

@xijo xijo commented Feb 10, 2020

Hello everyone,

This PR is referring to the following issue #3645 which is not yet fixed.

If ModalManager is constructed with defaultProps there is still a chance that document.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

@taion
Copy link
Member

taion commented Feb 10, 2020

this isn't semantically correct; we need the modal manager to be shared

@xijo
Copy link
Contributor Author

xijo commented Feb 10, 2020

@taion Could you please elaborate? What do you mean by shared? And what isn't semantically correct? Thanks for your feedback!

@taion
Copy link
Member

taion commented Feb 10, 2020

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.

@xijo
Copy link
Contributor Author

xijo commented Feb 10, 2020

I see you point. We could also do it like that, as long as it's only going to instantiate the ModalManager when the Modal is being rendered, and therefore document.body is ready.

I'll update the PR accordingly.

@xijo xijo force-pushed the attempt_to_fix_document_body_missing_during_modal_import branch 2 times, most recently from 30e5541 to 5372504 Compare February 10, 2020 19:17
@xijo
Copy link
Contributor Author

xijo commented Feb 11, 2020

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();
Copy link
Member

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

Copy link
Contributor Author

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.

@taion
Copy link
Member

taion commented Feb 11, 2020

please just take a look at the logic in react-overlays and use that here. that logic does the right thing.

@xijo xijo force-pushed the attempt_to_fix_document_body_missing_during_modal_import branch from 5372504 to 87b89aa Compare February 11, 2020 18:59
@xijo xijo requested a review from jquense February 13, 2020 08:54
@jquense jquense merged commit 5aa2be1 into react-bootstrap:master Feb 13, 2020
@jquense
Copy link
Member

jquense commented Feb 13, 2020

thanks!

@xijo xijo deleted the attempt_to_fix_document_body_missing_during_modal_import branch February 14, 2020 17:59
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

Successfully merging this pull request may close these issues.

None yet

3 participants