-
Notifications
You must be signed in to change notification settings - Fork 48.4k
Uncaught Invariant Violation: Must be mounted to trap events when replacing an image with a link to an image #6371
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This trapping code got moved around a bit in 15, can you paste the stack for that repro? A consistent repro we can run would be helpful, so I appreciate you trying, let us know if you do get it working. The high level assumption here - we have some special event code for some events which don't bubble on some dom nodes. In this case it's the img in the header and likely a load (or error) event. It's possible the event is firing when componentWillUnmount is happening (which is in turn triggering a rerender and removing the img), but I would have thought that (a) this happens outside the current event loop and (b) the node is removed and event listener removed before this could happen. This unmount, setState handling code is pretty confusing though. Perhaps @spicyj knows what's up. |
I don't know offhand. A repro case would be very helpful – you shouldn't ever see that error. |
I have this warning as well. I use:
In my case it happens when I'm transitioning from one page of the same component to another and dispatching an action in |
@Dattaya that would be awesome, I haven't had time to do this myself. Thanks! |
I'm not sure my case is worth investigating, the error happens only when both
Now in the console you should see an error: |
@gaearon Sounds like this might be redux related, especially if it requires the redux devtools extension be installed. Should we move this over to that repository? |
I am receiving the same error in a somewhat similar context. I am trying to push a route on a page before a component is mounted. Inside If I try the same logic inside Example:
package.json has
|
@jimfb It should be impossible to trigger this error in React, so it is a React bug even if all the repro cases use Redux. |
@spicyj Ah, yeah, probably true. I have no idea what the redux devtools extension is doing, but it's entirely conceivable that they're reaching into internals, in which case, it would not be a React bug. If the issue doesn't repro without the redux-devtools (which @Dattaya's comment seemed to imply) then that would seem to imply it might not be a React bug. But yeah, that's why I asked @gaearon. |
Redux DevTools don’t touch React internals, it’s only userland code. |
I can’t vouch for the Chrome extension though. |
Yes, sorry for any ambiguity, I was referring to the chrome extension. |
@gaearon, that's strange. In the extension's injected script we don't use React at all, except the fact that it is imported from I just checked the example above and the error appears also when the extension is disabled (@Dattaya, could you confirm?). So, it doesn't seem to be related to Redux DevTools or the Chrome extension. |
@zalmoxisus I can confirm that the error also appears when the extension is disabled. Using react |
@zalmoxisus, that's correct, sorry about the confusion, I might have looked in the wrong console, when trying to replicate it in my project without dev tools. It's completely unrelated to Dev Tools. |
I'm having the same problem and after a bit of debugging I see that callbacks queued using The actual error message is a bit different in each case but it occurs in both I'm using the same stack and the weird part is that this error occurs when I click on the Also confirming that it's completely unrelated to Dev Tools. Adding another stack trace. Note that in my case it is a Related #6538 |
We're seeing the same stack trace as @stream7. We only see this error if the component which is unmounted on route change contains an
We also see this error in |
@Dattaya Thanks for posting the repro case. Hopefully one of us can look into this. |
Here's an additional codepen showing the http://codepen.io/chelzwa/pen/JXZeOL?editors=1010 Steps to reproduce:
Although my specific error is different than @Dattaya's, it seems likely to be related to the same cause, as I also found that this happens only if I include react-router-redux in the project. |
Apparently both Not sure what this means though. |
@gaearon @spicyj do you know if this is expected behaviour? It sounds like it isn't but if we don't know this for sure we can't use it to debug further. |
Minimal repro thusfar: var callbacks = [];
function emitChange() {
callbacks.forEach(c => c());
}
class App extends React.Component {
constructor(props) {
super(props);
this.state = { showChild: true };
}
componentDidMount() {
this.setState({ showChild: false });
}
render() {
return (
<div>
<ForceUpdatesOnChange />
{this.state.showChild && <EmitsChangeOnUnmount />}
</div>
);
}
}
class EmitsChangeOnUnmount extends React.Component {
componentWillUnmount() {
emitChange();
}
render() {
return null;
}
}
class ForceUpdatesOnChange extends React.Component {
componentDidMount() {
this.onChange = () => this.forceUpdate();
this.onChange()
callbacks.push(this.onChange);
}
componentWillUnmount() {
callbacks = callbacks.filter(c => c !== this.onChange)
}
render() {
return (
<div key={Math.random()} onClick={function(){}} />
)
}
}
ReactDOM.render(<App />, document.getElementById('container')); Thanks Dan for helping reduce! |
#2410 is a known problem which might cause this but otherwise that should only happen if something throws an exception (and maybe not even then). |
But it's not an exact duplicate, so I don't want to close this one out as a duplicate. In this case, it's something to the effect of: redux setting state on a component after/while react-router is unmounting it (or its parent). But it's a very similar phenomenon that occurs due to an unmount higher up in the tree within the same transaction. |
Well, I have the same problem, y tried removing Dev Tools and it works.... so... |
Note: this is exactly the same as #6538. The message depends on what you render (#6538 (comment)), but the underlying issue is explained in #6538 (comment). |
Fixes facebook#2410. Fixes facebook#6371. Fixes facebook#6538. I also manually tested the codepen in facebook#3762 and verified it now works.
Fixes facebook#2410. Fixes facebook#6371. Fixes facebook#6538. I also manually tested the codepen in facebook#3762 and verified it now works.
I'm having a hard time narrowing a repro down for this and there seem to be a lot of required moving parts, so I'll try to give as much information as I can.
Relevant snippet of package.json:
Our routes look something like this:
LayoutNoFooter
simply wrapsLayout
and passes an additional prop in.I have this component in the
Header
, which is rendered byLayout
: https://gist.github.com/aaronjensen/86c9643ecc53ad4e9006Header
is a react-redux connected component.Page1
has acomponentWillUnmount
that dispatches an action that ultimately togglessearchMode
inHeaderLogo
.When I go from
Page1
toPage2
the invariant violation fires.If I
setTimeout
the action dispatch incomponentWillUnmount
it appears to work fine. If I replaceLayoutNoFooter
withLayout
it appears to work fine.The invariant violation is on the
img
tag of theHeaderLogo
I've tried building a repro in codepen, with a similar structure
setState
calls to simulate react-router and redux, but I suspect they are doing more that would require me to actually build a repro w/ those technologies. If that would be helpful, I can work on it over time and hopefully repro it. Maybe there's enough info here, however. Thanks!The text was updated successfully, but these errors were encountered: