0

We just installed an error-tracker for our Ember-application, and the only error that is reported is Cannot read property 'find' of undefined. The code that cause this error is within a component, and looks like this:

this.set('interval', setInterval(() => {
  const current = this.get('counter') - 1;
  this.set('counter', current);
  this.$().find('.countdown-number').text(current); // <- error here
}, 1000));

I don't understand how this can happen. How can $() be undefined, since it's a part of the ember framework?

According to the error-tracker, it happens for a bunch of different browsers, latest Chrome for example. I however can't reproduce the error in any browser.

I know this isn't the "ember way" of updating a text in a div, but I would prefer to not have to rebuild a lot, I just want to fix the bug with as little changes as possible.

0

1 Answer 1

1

this.$() will be undefined if component is destroyed or didn't render properly. Make sure you call this.$() only when component is in DOM and on willDestroyElement you remove all events that could access this.$().

Sign up to request clarification or add additional context in comments.

4 Comments

Ahh, that actually makes a lot of sense! Updated the code in the question above, and as you can see it's an interval that probably keeps going even after the component is destroyed. Adding clearInterval to willDestroyElement might be a solution, i'll try it out.
Definitely this should fix things. You have reference stored as interval so it should be quick fix. :)
It works perfectly, not a single error for 4 hours now, while we previously had several every minute. Thanks! :)
Very happy to hear! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.