Skip to content

Commit

Permalink
fix(plugins/plugin-kubectl): in browser clients, CurrentContext/Names…
Browse files Browse the repository at this point in the history
…pace widgets may get stuck

part of #7656
  • Loading branch information
starpit authored and k8s-ci-robot committed Jun 17, 2021
1 parent e551b4d commit 4f2857f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
10 changes: 6 additions & 4 deletions plugins/plugin-kubectl/components/src/CurrentContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
eventChannelUnsafe,
getCurrentTab,
getTab,
inBrowser,
Tab,
TabState,
encodeComponent,
Expand Down Expand Up @@ -66,6 +65,9 @@ function KubernetesIcon() {
)
}

export let ready = false
eventBus.once('/tab/new', () => (ready = true))

export default class CurrentContext extends React.PureComponent<Props, State> {
private readonly handler = this.reportCurrentContext.bind(this)
private readonly handlerForConfigChange = this.getCurrentContextFromChange.bind(this)
Expand Down Expand Up @@ -257,8 +259,8 @@ export default class CurrentContext extends React.PureComponent<Props, State> {
*
*/
public componentDidMount() {
if (inBrowser()) {
eventBus.on('/tab/new', this.handler)
if (!ready) {
eventBus.once('/tab/new', this.handler)
} else {
this.handler()
}
Expand All @@ -270,7 +272,7 @@ export default class CurrentContext extends React.PureComponent<Props, State> {

/** Bye! */
public componentWillUnmount() {
// eventBus.off('/tab/new', this.handler)
eventBus.off('/tab/new', this.handler)
eventBus.off('/tab/switch/request/done', this.handlerNotCallingKubectl)
eventBus.offAnyCommandComplete(this.handler)
offKubectlConfigChangeEvents(this.handlerForConfigChange)
Expand Down
16 changes: 4 additions & 12 deletions plugins/plugin-kubectl/components/src/CurrentNamespace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@ import React from 'react'

import { Icons, ViewLevel, Select, TextWithIconWidget } from '@kui-shell/plugin-client-common'

import {
eventBus,
inBrowser,
i18n,
eventChannelUnsafe,
getTab,
Tab,
TabState,
pexecInCurrentTab
} from '@kui-shell/core'
import { eventBus, i18n, eventChannelUnsafe, getTab, Tab, TabState, pexecInCurrentTab } from '@kui-shell/core'

import {
kubectl,
Expand All @@ -38,6 +29,7 @@ import {
offKubectlConfigChangeEvents
} from '@kui-shell/plugin-kubectl'

import { ready } from './CurrentContext'
import { isInternalNamespace } from '@kui-shell/plugin-kubectl/heuristics'

interface Props {
Expand Down Expand Up @@ -138,8 +130,8 @@ export default class CurrentNamespace extends React.PureComponent<Props, State>
*
*/
public componentDidMount() {
if (inBrowser()) {
eventBus.on('/tab/new', this.handler)
if (!ready) {
eventBus.once('/tab/new', this.handler)
} else {
this.handler()
}
Expand Down

0 comments on commit 4f2857f

Please sign in to comment.