Did not expect componentDidMount timer to start while render timer is still in progress for another instance
Not sure this should be filed as a bug, or if this is intended behaviour, in which case it would be more of a feature request, for something that we lost since the last few versions.
Which is more specific error logging.
Since the last few version this error shows up too many times, without any usable stack-trace:
There is an internal error in the React performance measurement code. Did not expect componentDidMount timer to start while render timer is still in progress for another instance.
This mainly occurs when a prop or state is not defined. This wouldn't be a big problem if I could stacktrace it, but in this case I cannot lead it back to any related component, I have to go off on what I changed last.
I do use redux and the stacktrace does go back to createStore and then connect, but this should not be related since this error shows up regardless of which element has an undefined property.
It is also often accompanied by:
Uncaught TypeError: Cannot read property '_currentElement' of null
How do I debug this error? Or are there plans to improve this?
This is on my list, I’ll look at fixing it this week. To be clear, this warning itself is not valuable to you, you should look for an earlier error in your code instead. This is just a symptom; the root cause is as you described:
This mainly occurs when a prop or state is not defined.
An earlier error occurred in your app, so scroll the console up and look at the original error, not this warning, or Cannot read property '_currentElement' of null.
@gaearon Scrolling back there is no related error being logged, but React does choke on it, which is both strange and annoying.
This probably means you are using a Promise polyfill that swallows errors. Could that be the case?
@gaearon, that might be possible, not sure how to fix that though, I do get occasional errors from bluebird that a promise is not returning anything, I still have to find a solution for that.
- I get the same exact warning when props/state not defined
- I scroll up in the console and there is no related error so i can't pin point which prop/state is undefined
- I am using bable polyfill for async/await
- My silly workaround for this was to put console.error(err) in all my catch statements and now at least i know the name of the prop/state which is undefined.
I got the same Error today. As soon as I subscribe to a reducer form 2 different components loaded simultaneously on screen and trying to access the same reducer it throws the error.
I am using Redux.
@AdityaAthavale interesting, it crossed my mind that it was because of multiple dispatches at the same time, but through nothing of it. This might be one of the causes
I just got this error while trying to implement dimensional charts using crossfilter.js. I believe one of my crossfilter operations is causing the choke..
import React from 'react';
import crossfilter from 'crossfilter';
import update from 'react-addons-update';
class DimensionalCharts extends React.Component {
constructor(props) {
super(props);
this.state = {
data: [],
charts: [],
filter: {},
index: {},
indexGroup: {},
value: {},
valueGroup: {},
index2D: {},
index2DGroup: {}
};
}
componentWillMount() {
const data = range(256).map((i) => [ i, randomGaussian() + 8 ]),
filter = crossfilter(data),
index = filter.dimension((d) => d[0]),
indexGroup = index.group().reduceSum((d) => d[1]),
value = filter.dimension((d) => d[1]),
valueGroup = value.group().reduceSum((d) => d[1]),
index2D = filter.dimension((d) => d),
index2DGroup = index2D.group();
this.setState({
data, filter,
index, indexGroup,
value, valueGroup,
index2D, index2DGroup
});
this.filterAll();
}
filterAll() {
const { index, value, index2D } = this.state;
[ index, value, index2D ].forEach((dim) => dim.filterAll());
}
redrawAll() {
store.charts.forEach((chart) => chart.redraw());
}
addChart(chart) {
const newState = update(this.state, {
charts: { $push: [ chart ] }
});
this.setState(newState);
}
}
I just got this by having a faulty function import
As I said above this warning has zero effect on your errors. I will remove it soon but for now it is absolutely irrelevant and you can ignore it.
If you don't see the real error, this is a problem with your setup. Adding another comment in this thread about the type of error that caused it will not help us. It will occur for any error, so there is no need to describe many different ways you could cause an error in JavaScript. This is not specific to React or Redux in any way.
What will help us is if you reproduce this warning without an error before it, and share that code. Trim down your project, publish the result and instructions to reproduce, and send a link here. Then I can take a look at why your error is being swallowed. But again, if errors are swallowed in your setup, us removing this warning won't fix your problem. Your errors will keep getting silently swallowed because there is something else hiding them, and we don't know why. So please only add new comments if you have a project showing how an error gets swallowed.
Thanks!
@gaearon sorry for posting without more info. I posted it because I was getting this warning without an prior errors being thrown. The issue was that I was importing a function from another file, and then function had an artifact reference to a class it was once a part of. There were no errors thrown in the Xcode console. Here is a gist of trimmed down example of the code that did it: https://gist.github.com/dwilt/605aa6ca4257d8a9615979fdaa82f405
Hi guys I had a similar error in a browser console. And due of some debugging I found uncatched exception in my componentWillMount/componentWillUnmount functions. That exception did not traced to the browser console. When I wrapped my code with a try/catch black the message from react disappeared and the catch block execute with an error.
componentWillMount(){
try {
doSomeStuff()
} catch (e) {
console.error(e)
}
}
So I guess you should try to wrap a code inside component's lifecycle functions with try/catch
UPD all this stuff only for catch an error. not for prod use
No, adding your own try/catch is not the recommended solution, it's working around the real problem (something swallows your exceptions). It would be great if you could share your project. I could take a look at why your exceptions are being swallowed.
@gaearon Can you explain what the error tries to describe? Even if it is not relevant for the original issue.
"Did not expect componentDidMount timer to start"
Who/which function/component did not expect it? Does every element get a timer? or is there a central timer that starts?
"while render timer is still in progress for another instance"
Which other instance? What does that other instance have to do with this instance?
Is the error wrongly outputted (a.ka. not the real error) because a previous error was swallowed, and if yes then why is it outputted or how?
These might be very specific questions to answer, but the fact is that people are coming here to solve this mysterious error, that only shows up in specific cases. ( the intended, but also unindended cases)
We have no way to distinguish between the so called real error and one that is caused by something else.
I think letting people post their specific circumstances here is more helpfull to get a grip on it, than saying that posting is useless or irrelevant. Or that it occurs for any error is simply not true.
@gaearon of cause try/catch only for detecting a problem. It's was surprise for me that exceptions in these functions are not logged to console by default.
Thanks for clarifying. But errors in these functions should be logged. There’s nothing special about React lifecycle methods from browser’s point of view. If they’re not, that’s a problem with your setup, not with React itself. If you share the project reproducing it, I can take a look at why this happens.
@BlockChange
Can you explain what the error tries to describe? Even if it is not relevant for the original issue.
Sure.
Calls to lifecycle methods are instrumented with performance measurement calls in development.
For example, we start a timer, then call your componentDidMount on the next line, then stop the timer. The same happens for render() method. This lets us later calculate how much time was spent in each component for ReactPerf measurements.
Normally every onEndLifeCycleTimer call corresponds to onBeginLifeCycleTimer call.
To ensure this, onBeginLifeCycle sets a variable called currentTimerType, and onEndLifeCycleTimer sets it back to null. We make sure that we don’t forget to call onEndLifeCycleTimer for some edge case by emitting a warning if the “current timer” is set to something other than null when the timer starts.
My intention was to use this warning to prevent people forgetting to call onEnd... when working on React itself. So this is a safety measure. I also wanted to enable it in user code in case there is some pattern in which the timer gets messed up, which we should fix.
The one thing I missed is that if the app’s code throws during a lifecycle hook like componentDidMount, the “current” timer will not be reset, and the warning will appear as a false positive. I didn’t think it’s a big deal because I thought that you’d see the real error anyway just above this warning.
But apparently it is so common that errors get swallowed in React apps that people just don’t see the original error 😞 . I’m not sure why—this is why I’m asking people to share their examples. Maybe it’s a bad Promise polyfill, maybe it’s a catch block above setState that people don’t realize swallows exceptions. It’s hard to guess.
I’m currently busy with create-react-app and couldn’t dedicate enough time into looking into this yet, sorry!
I have this error when accessing a prop from the constructor
constructor() {
super()
const { show } = this.props
}
removing them or moving these statements to componentWillMount will help
@vinhlh you have to do
constructor(props) {
super(props);
const { show } = props;
}
@vinhlh
Have you had a chance to read through my replies above? You’ll currently have this warning with any error in your code but you should see the real error alongside it. Is it not there? If not, please share a project reproducing this.