# Why am I getting the Cannot read properties of undefined (reading 'pushEvent') error?

**URL:** <https://community.grafana.com/t/why-am-i-getting-the-cannot-read-properties-of-undefined-reading-pushevent-error/133040>\
**Category:** Grafana Plugin Development\
**Created:** [September 26, 2024, 6:17pm UTC](https://community.grafana.com/t/why-am-i-getting-the-cannot-read-properties-of-undefined-reading-pushevent-error/133040 "2024-09-26T18:17:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxymzakharkiv](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@maxymzakharkiv](https://community.grafana.com/u/maxymzakharkiv)\
**Post date:** [September 26, 2024, 6:17pm UTC](https://community.grafana.com/t/why-am-i-getting-the-cannot-read-properties-of-undefined-reading-pushevent-error/133040/1 "2024-09-26T18:17:04Z")

</div>

I am developing a custom table visualization. I am using a custom hook called `useBlinkingCells`, and for some reason, when I create a new table, I get the error “Cannot read properties of undefined (reading ‘pushEvent’)” (screenshot of the error below). I found that the error occurs specifically in this custom hook; when I remove it, the error disappears. What is the problem and how can I solve it?

Thank you in advance for your help! Here is the link to the repository with the code: [GitHub - MaxymZakharkiv/Test1](https://github.com/MaxymZakharkiv/Test1).

 ![Знімок екрана 2024-09-26 о 21.05.29](https://us1.discourse-cdn.com/grafana/original/3X/c/7/c785c663c27c84c57f00904f2b831dc820e05501.png)

---

<div class="post-metadata">

**Author:** ![academo](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@academo](https://community.grafana.com/u/academo)\
**Post date:** [September 30, 2024, 7:19am UTC](https://community.grafana.com/t/why-am-i-getting-the-cannot-read-properties-of-undefined-reading-pushevent-error/133040/2 "2024-09-30T07:19:30Z")

</div>

Hi.

I didn’t follow through all the logic in your code but it is most likely you have a race condition e.g… trying to subscribe or unsubscribe to specific events before the objects are ready, or trying to access objects before they are ready.

as I side note.[Don’t use direct general dom operations in your code.](https://github.com/MaxymZakharkiv/Test1/blob/main/index.tsx#L58) This will most likely cause side effects in your plugin and in Grafana itself and there are some (optional) security options in Grafana that will prevent your plugin from accessing elements outside of your panel rendering scope.

---

<div class="post-metadata">

**Author:** ![maxymzakharkiv](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@maxymzakharkiv](https://community.grafana.com/u/maxymzakharkiv)\
**Post date:** [September 30, 2024, 8:25am UTC](https://community.grafana.com/t/why-am-i-getting-the-cannot-read-properties-of-undefined-reading-pushevent-error/133040/3 "2024-09-30T08:25:26Z")

</div>

I commented the code with the dom operation, but the error did not disappear, I also investigated that the error appears if you first select a custom visualization, and then data from the datasource, if on the contrary the error disappears

---

<div class="post-metadata">

**Author:** ![academo](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@academo](https://community.grafana.com/u/academo)\
**Post date:** [September 30, 2024, 8:57am UTC](https://community.grafana.com/t/why-am-i-getting-the-cannot-read-properties-of-undefined-reading-pushevent-error/133040/4 "2024-09-30T08:57:17Z")

</div>

I mentioned the dom operations as a problem for the plugin in general not the cause of your error.

> investigated that the error appears if you first select a custom visualization, and then data from the datasource

This indicates a race condition or a lack of validation, where your panel code is assuming data is always present when is not. You should make sure to always validate the objects that come to your panel contain the data you need before looping objects or using their values.

---

<div class="post-metadata">

**Author:** ![maxymzakharkiv](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@maxymzakharkiv](https://community.grafana.com/u/maxymzakharkiv)\
**Post date:** [September 30, 2024, 9:34am UTC](https://community.grafana.com/t/why-am-i-getting-the-cannot-read-properties-of-undefined-reading-pushevent-error/133040/5 "2024-09-30T09:34:22Z")

</div>

I don’t fully understand, can you please show with an example what you mean?

---

<div class="post-metadata">

**Author:** ![academo](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@academo](https://community.grafana.com/u/academo)\
**Post date:** [September 30, 2024, 10:07am UTC](https://community.grafana.com/t/why-am-i-getting-the-cannot-read-properties-of-undefined-reading-pushevent-error/133040/6 "2024-09-30T10:07:28Z")

</div>

you should take a look first at what a [race condition](https://en.wikipedia.org/wiki/Race_condition) is and what defensive programming (in terms of input validation and defensive checks).

For an example, imagine your panel is simply accessing the first series coming as props so you do a code like this:

```typescript
function SimplePanel({ data: Props }) {  
   const frame = data.series[0];
   // do something with frame
}

```

the problem with this code is that you are assuming: `data` is not undefiend and it is an object, `data.series` is not undefined, it is an array and it is populated with at least one item.

In javascript you can use things like [optional chaining](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) to better handle these cases:

```typescript
function SimplePanel({ data: Props }) {  
   const frame = data?.series?.[0];
   if (frame !== undefined){
       // do something with frame
   }
}

```

This second snippet is safer because you won’t be trying to access elements that don’t exist.

This is of course a very simple example, you can be for example, trying to access objects from `@grafana/runtime` before they are ready (though Grafana greatly prevent you from doing this), or trying to use APIs that can’t be used yet or in that specific moment.

What I recommend you to debug your hook if you don’t know where to start, is to start commenting pieces of your code (of course keeping it in working order) and see what part of the code you comment finally eliminates the error, like you did with removing the hook usage, but inside your hook.

once you identify which lines of code are causing the error, try to see if you are missing validations like this where you are trying to access objects or APIs that are not ready to use.

---

<div class="post-metadata">

**Author:** ![maxymzakharkiv](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@maxymzakharkiv](https://community.grafana.com/u/maxymzakharkiv)\
**Post date:** [September 30, 2024, 10:11am UTC](https://community.grafana.com/t/why-am-i-getting-the-cannot-read-properties-of-undefined-reading-pushevent-error/133040/7 "2024-09-30T10:11:35Z")

</div>

It seems to have worked, thank you very much!!!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/grafana/original/2X/e/ef5308cc58c9e5a13187b5012eb99f406928462f.png) [@system](https://community.grafana.com/u/system)\
**Post date:** [September 30, 2025, 10:11am UTC](https://community.grafana.com/t/why-am-i-getting-the-cannot-read-properties-of-undefined-reading-pushevent-error/133040/8 "2025-09-30T10:11:47Z")

</div>

Closed on September 30, 2025, 10:11am UTC

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
