-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 relies on document as default renderNode, breaks SSR #712
Comments
The constraint here is that Semantic-UI's CSS requires an immediate child relationship from In order to prevent a |
In terms of best practices: I'm using My only thoughts then are either patch the SUI CSS or make it |
+1 to what @dcurletti said
I've yet to come across a work around outside of forgetting about using a modal. |
@strues The easiest way to get around this is to render on the client. Example: import React from 'react';
import { Header, Icon, Modal } from 'semantic-ui-react';
class Test extends React.Component {
state = {
isMounted: false
};
componentDidMount() {
this.setState({isMounted: true});
};
render() {
return (
<div>
{
this.state.isMounted &&
<Modal trigger={<button className="ui primary button">Open Modal</button>}>
This works
</Modal>
}
</div>
)
}
} |
@nolandg @dcurletti @strues - Given that this isn't fixed I'm going to reopen it. Would one of you be able to provide a minimal example that reproduces this issue? I'm not too familiar with server-side rendering so I don't even know how I'd go about trying to reproduce this. A PR with a bug fix would also be welcome 😁 (cc @levithomason 😉) |
I'm using Meteor + react-router + react-router-ssr. Not exactly minimal for this issue. Is someone already using something simpler so I don't have to make something from scratch? |
@jcarbo it looks like the issue is that // abbreviated Modal render()
<Portal mountNode={this.getMountNode()} /> Based on the above feedback, the only issue we need to fix is that we should not try to access ProposalI think we should avoid setting state on mount as this is an antipattern. It also causes an unnecessary render and complicates testing. I propose instead we simply render
I'll ship this and see how it goes! |
@nolandg @dcurletti @strues I'm curious whether or not you're using other components that also access the |
I've added #806 to address this issue in all components that access document/window. Please take a look, if you can test that branch, it would be much appreciated as well. |
@levithomason I just added Search (literally an hour ago) and I was not getting a document error. I quickly glanced at #806 and I think it'll do the trick, but give me some time tonight, for sure by tomorrow, to test it. Sorry I didn't add a test case, my current setup is a fork from here: https://github.com/erikras/react-redux-universal-hot-example and won't be that easy to create a test gist with. |
I'll hold off until you are able to test it, thanks much! |
I went ahead and released the potential fix in |
@levithomason (sorry for the tardiness). Unfortunately this did not fix it. #806 crashes in a different place now and complains about the window. error given was: ReferenceError: window is not defined
/some/path/node_modules/semantic-ui-react/dist/commonjs/lib/isBrowser.js:10:97) |
Shoot, I looked at this line the other day too and forgot to comment: |
This bypasses errors for server-side rendering by just not rendering the component when the window object is absent. That leads to
because the component is not rendered on the server, but it is rendered on the client. Is this expected? |
That is the current design, however, I'm not sure as to the best practice here. See: We cannot render the Modal as it requires a |
Line 117 of Modal.js uses
document
as the mount node ifthis.props.mountNode
is absent. Thus if you don't specifymountNode
, server-side rendering fails because there is nodocument
.Modal.js:117
The only workaround I can figure out is to track if the parent component has been mounted with a manually set
this.state.hasMounted
and then only render theModal
aftercomponentDidMount
has run. This makes the markup awkward and adds complexity.Is there another option? Could Modal.js guard against trying to use
document
when it's not defined? Couldn't it just default to rendering in its parent like other components?The text was updated successfully, but these errors were encountered: