# Custom plugin doesn't autoRefresh when added to a dashboard

**URL:** https://discuss.elastic.co/t/custom-plugin-doesnt-autorefresh-when-added-to-a-dashboard/303766
**Category:** Kibana
**Tags:** kibana-plugin-development
**Created:** [May 2, 2022, 7:10pm UTC](https://discuss.elastic.co/t/custom-plugin-doesnt-autorefresh-when-added-to-a-dashboard/303766 "2022-05-02T19:10:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dmprieto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dmprieto/32/105139_2.png) [@dmprieto](https://discuss.elastic.co/u/dmprieto)
#### Post date: [May 2, 2022, 7:10pm UTC](https://discuss.elastic.co/t/custom-plugin-doesnt-autorefresh-when-added-to-a-dashboard/303766/1 "2022-05-02T19:10:08Z")

</div>

Hi  
I developed a custom plugin for Kibana 7.17.0 and when I enable the autoRefresh in the Visualization editor page it works ok, but when I add the custom plugin to an empty dashboard it doesn't refresh when autoRefresh is enabled in the dashboard

Also, I noticed that if besides the custom plugin I add a default Kibana plugin like "Metric" of "Cloud Tag" to the dashboard, the custom plugin starts to autoRefresh as expected.

I see that not all of Kibana default plugins work with the dashboard autoRefresh, for example the Markdown plugin autoRefreshes in the editor but not when added to a dashboard.

Besides calling the handler.done after the custom plugin is rendered, is there anything additional I need to implement in the custom plugin to make it work with the autoRefresh of the dashboards?

---

<div class="post-metadata">

### Author: ![Mikhail\_Shustov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikhail_shustov/32/49186_2.png) [@Mikhail\_Shustov](https://discuss.elastic.co/u/Mikhail_Shustov)
#### Post date: [May 3, 2022, 9:06am UTC](https://discuss.elastic.co/t/custom-plugin-doesnt-autorefresh-when-added-to-a-dashboard/303766/2 "2022-05-03T09:06:10Z")

</div>

> [@dmprieto](#):
>
> autoRefresh

Your plugin needs to re-fetch data manually. It can learn when it's time to fetch data with [Autorefresh API](https://github.com/elastic/kibana/blob/1303044ae7d3452116ee1f8c4826b48b3dddfb45/src/plugins/data/README.mdx#autorefresh)

---

<div class="post-metadata">

### Author: ![dmprieto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dmprieto/32/105139_2.png) [@dmprieto](https://discuss.elastic.co/u/dmprieto)
#### Post date: [May 17, 2022, 6:58pm UTC](https://discuss.elastic.co/t/custom-plugin-doesnt-autorefresh-when-added-to-a-dashboard/303766/4 "2022-05-17T18:58:47Z")

</div>

I was able to include the autoRefreshFetch code in my plugin and still the auto refresh loop only executed once when the plugin is inside a dashboard.

I debugged the code and in auto\_refresh\_loop.ts I saw that the following condition never happened, so the counter didn’t restart

```auto
if (pendingDoneCount === 0) {

start();

}

```

In the end I found out that the issue is happening in this file [**https://github.com/elastic/kibana/blob/7.17/src/plugins/dashboard/public/application/lib/sync\_dashboard\_filter\_state.ts**](https://github.com/elastic/kibana/tree/9d5aca591b08f93729b702bcd47311cb33e227a8) , in this section of the code:

`// best way in a dashboard to estimate that panels are updated is to rely in search session service state waitUntilNextSessionCompletes$(search.session).pipe(finalize(done))`

The session needs to be marked as complete, and after that the auto\_refresh\_loop done method is called. I found out that in the timeline plugin they are calling trackSession and untrackSession and this triggers changing the session state to complete, see [kibana/timelion\_request\_handler.ts at 7.17 · elastic/kibana · GitHub](https://github.com/elastic/kibana/blob/7.17/src/plugins/vis_types/timelion/public/helpers/timelion_request_handler.ts)

After calling those methods in my code the auto refresh worked and I didn’t have to call the autoRefresh API. The way that Kibana handles the dashboard session was affecting the autoRefresh logic, not sure if this only happens in Kibana 7.17.0

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 14, 2022, 6:59pm UTC](https://discuss.elastic.co/t/custom-plugin-doesnt-autorefresh-when-added-to-a-dashboard/303766/5 "2022-06-14T18:59:18Z")

</div>

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