-
Notifications
You must be signed in to change notification settings - Fork 45.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
ReferenceError: document is not defined #1866
Comments
I have the same problem |
I'm having the same problem. |
FYI, we worked around it by using |
Wow this sounds like a big regression. Can you construct a simple repro case? |
I will try but I probably won’t be able to until Sunday the earliest. Frankly, the error doesn’t happen with for every |
This might happen always if you setState within a componentWillMount? Agree that we need to fix this. |
For me it happens when I do setState in componentWillMount. |
Oh, setState() is probably going through ReactUpdates which is using the (browser-specific as of 0.11) ReactReconcileTransaction I think. |
Yes, we are using |
@gasl maybe? why are you doing that vs |
Here’s the part of the stack trace (
|
This is the most simple example that reproduces the problem: var React = require('react');
var HelloMessage = React.createClass({displayName: 'HelloMessage',
componentWillMount:function () {
this.setState({name: "Pete"});
},
render: function() {
return React.DOM.div(null, "Hello ", this.props.name);
}
});
console.log(React.renderComponentToString(HelloMessage({name: "John"}))); |
Trying to figure out if the right move is to fix |
The former; we've always said this is supported. |
but why do we support it? seems like "more than one way to do it"... |
One use case is computing something based on props in both componentWillMount and componentWillReceiveProps; you can make a helper and call it in both places. |
getInitialState() {
return helper(this.props);
}
componentWillReceiveProps(nextProps) {
this.setState(helper(nextProps));
} does the same thing, no? |
...when calling setState from within a componentWillMount. Fixes facebook#1866. Test Plan: jest
@petehunt: Based on your example, I can see now that calling I’m ok with a breaking change in |
Don't initialize reconcile transaction on server
We're going to put out 0.11.1 with this (and a couple other ride-alongs). Thanks for bringing it to our attention! |
👍 Thanks 😄 |
Hi guys! The issue referenced above looks (reactjs/react-rails#146) related to this one... input welcome! |
After upgrading from React 0.10 to 0.11 our
componentWillMount
handler fires during server-side rendering and ends up ingetActiveElement
which requires access to the DOM, i.e.document
:Redacted stack trace:
The text was updated successfully, but these errors were encountered: