Skip to content

[fixed] Restore Modal.setAppElement() functionality #108

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

Merged
merged 1 commit into from
Mar 26, 2016
Merged

[fixed] Restore Modal.setAppElement() functionality #108

merged 1 commit into from
Mar 26, 2016

Conversation

evoyy
Copy link
Contributor

@evoyy evoyy commented Nov 26, 2015

Maybe I have misunderstood, but this commit will anchor the modal to the specified appElement, as I had expected it to from the README. It fixes #107.

@@ -7,12 +7,15 @@ var elementClass = require('element-class');
var renderSubtreeIntoContainer = require("react-dom").unstable_renderSubtreeIntoContainer;

var SafeHTMLElement = ExecutionEnvironment.canUseDOM ? window.HTMLElement : {};
var AppElement = document.body;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would throw an error on Isomorphic/Universal applications :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@azaharakis

I don't have experience with isomorphic apps, but I guess it's because document.body doesn't exist at compile time. Would it work if I do it like this instead?

    var AppElement;

    componentDidMount: function() {
        ...
        (AppElement || document.body).appendChild(this.node);
        ...
    },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems there's a comment on every PR about something breaking when rendered on the server. Perhaps it's time for a simple unit test to catch these issues. The dev community is pretty equally split on those that write isomorphic apps and those who don't, as such we can't expect everyone that works on this to know that what they're doing is going to break something.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var AppElement = ExecutionEnvironment.canUseDOM ? document.body : {appendChild: function() {}};

That will provide safe usage for server side.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't understand. If AppElement === {appendChild: function() {}}, surely AppElement.appendChild(this.node) will do nothing. So the modal will not be appended to the DOM.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evoyy - yes, it would do nothing. That's the point on the server side, we're just creating a mock so that it doesn't try to access the DOM unless there's something there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, of course. I will amend my PR. Thanks.

@jpserra
Copy link

jpserra commented Dec 28, 2015

@evoyy
Copy link
Contributor Author

evoyy commented Dec 29, 2015

@jpserra Nice catch, thanks!

@cameronprattedwards
Copy link

Thanks for fixing this. Would love to see this get merged. 😃

@fakenickels
Copy link

Would love to get this on a release :D

@svenheden
Copy link
Contributor

Same here, would love to have this merged!

@feorex
Copy link

feorex commented Mar 24, 2016

+1 for this PR!

@claydiffrient
Copy link
Contributor

@evoyy This looks good, but could you squash the four commits down to one. It'll keep the git history a lot cleaner. Another great thing to have would be some specs testing things out.

@evoyy
Copy link
Contributor Author

evoyy commented Mar 25, 2016

@claydiffrient Squashed and specs added.

@claydiffrient claydiffrient merged commit fe46c63 into reactjs:master Mar 26, 2016
darchitetto added a commit to versionone/react-modal that referenced this pull request May 4, 2016
see react-modal >> [fixed] Restore Modal.setAppElement() functionality reactjs#108
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.

Modal.setAppElement() has no effect
9 participants