Browse Source

web: prevent status update loop in background

When leaving the status page while it is waiting for status data,
the callback happens when the status page is not mounted,
resulting in the update loop timer not being cleared.

This change prevents that by setting the visible attribute to false
when leaving the page, so that the update is not scheduled when
the page is not visible.

Change-Id: I9f3db68bb77c52d0f477b8322bbf52bd3cc81fe1
changes/43/636343/1
Tristan Cacqueray 2 years ago
parent
commit
00f4de3c51
1 changed files with 2 additions and 1 deletions
  1. +2
    -1
      web/src/pages/Status.jsx

+ 2
- 1
web/src/pages/Status.jsx View File

@ -84,7 +84,7 @@ class StatusPage extends Refreshable {
updateData = (force) => {
if (force || (this.visible && this.state.autoReload)) {
this.props.dispatch(fetchStatusIfNeeded(this.props.tenant))
.then(() => {if (this.state.autoReload) {
.then(() => {if (this.state.autoReload && this.visible) {
this.timer = setTimeout(this.updateData, 5000)
}})
}
@ -106,6 +106,7 @@ class StatusPage extends Refreshable {
clearTimeout(this.timer)
this.timer = null
}
this.visible = false
document.removeEventListener(
this.visibilityChangeEvent, this.visibilityListener)
}


Loading…
Cancel
Save