Skip to content

Commit

Permalink
fix(plugins/plugin-proxy-support): ProxyOfflineIndicator state does n…
Browse files Browse the repository at this point in the history
…ot survive unmount/remount

part of #7969
  • Loading branch information
starpit committed Sep 13, 2021
1 parent a198c9d commit a8226ca
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions plugins/plugin-proxy-support/src/view/ProxyOfflineIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ interface State {
}

export default class ProxyOfflineIndicator extends React.PureComponent<Props, State> {
/** To help maintain state across unmounts */
private static rememberedOffline = true

/** Cleanups for event listener registrations */
private cleaners: (() => void)[] = []

public constructor(props: Props) {
Expand All @@ -42,12 +46,12 @@ export default class ProxyOfflineIndicator extends React.PureComponent<Props, St
const proxyEnabled = proxyServer['enabled'] === undefined || proxyServer['enabled'] !== false
this.state = {
proxyEnabled,
offline: true
offline: ProxyOfflineIndicator.rememberedOffline
}
}

public componentDidMount() {
const onOnline = () => this.setState({ offline: false })
const onOnline = () => {
this.setState({ offline: false })
}
eventChannelUnsafe.on('/proxy/online', onOnline)
this.cleaners.push(() => eventChannelUnsafe.off('/proxy/online', onOnline))

Expand All @@ -57,6 +61,7 @@ export default class ProxyOfflineIndicator extends React.PureComponent<Props, St
}

public componentWillUnmount() {
ProxyOfflineIndicator.rememberedOffline = this.state.offline
this.cleaners.forEach(cleaner => cleaner())
this.cleaners = []
}
Expand Down

0 comments on commit a8226ca

Please sign in to comment.