Skip to content

Commit 8f51bb4

Browse files
committed
fix: in follow mode, switching from/back-to Application Logs results in blank tab content
We are not re-initializing the tailf stream
1 parent 5147ec8 commit 8f51bb4

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

plugins/plugin-codeflare/src/components/Terminal.tsx

+31-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,35 @@ import { ITheme, Terminal } from "xterm"
1919
import { FitAddon } from "xterm-addon-fit"
2020
import { Events } from "@kui-shell/core"
2121

22+
type WatchInit = () => {
23+
/**
24+
* Will be used to attach to an underlying streaming
25+
* provider of additional terminal output.
26+
*/
27+
on(eventType: "data", cb: (data: any) => void): void
28+
29+
/**
30+
* Terminate any streaming. Will be invoked un unmount, whenever
31+
* `this.props.streamer` is given.
32+
*/
33+
unwatch(): void
34+
}
35+
2236
interface Props {
37+
/** If given, the initial terminal output to render */
2338
initialContent?: string
24-
on?(eventType: "data", cb: (data: any) => void): void
25-
unwatch?(): void
39+
40+
/**
41+
* Commence/recommence streaming. Will be invoked on mount.
42+
*/
43+
watch?: WatchInit
44+
}
45+
46+
interface State {
47+
streamer?: ReturnType<WatchInit>
2648
}
2749

28-
export default class XTerm extends React.PureComponent<Props> {
50+
export default class XTerm extends React.PureComponent<Props, State> {
2951
private terminal: Terminal = new Terminal({
3052
convertEol: true,
3153
scrollback: 5000,
@@ -37,17 +59,19 @@ export default class XTerm extends React.PureComponent<Props> {
3759
public componentDidMount() {
3860
this.mountTerminal()
3961

40-
if (this.props.on) {
41-
this.props.on("data", this.terminal.write.bind(this.terminal))
62+
if (this.props.watch) {
63+
const streamer = this.props.watch()
64+
streamer.on("data", this.terminal.write.bind(this.terminal))
65+
this.setState({ streamer })
4266
}
4367
}
4468

4569
public componentWillUnmount() {
4670
this.unmountTerminal()
4771
this.cleaners.forEach((cleaner) => cleaner())
4872

49-
if (this.props.unwatch) {
50-
this.props.unwatch()
73+
if (this.state.streamer) {
74+
this.state.streamer.unwatch()
5175
}
5276
}
5377

plugins/plugin-codeflare/src/controller/tailf.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ async function tail(args: Arguments<FollowOptions>) {
3333

3434
if (process.env.FOLLOW) {
3535
const TailFile = await import("@logdna/tail-file").then((_) => _.default)
36-
const tail = new TailFile(fp, { startPos: 0, pollFileIntervalMs: 500 })
37-
tail.start()
38-
tail.on("tail_error", (err) => console.error(err))
3936

4037
return {
4138
react: React.createElement(Terminal, {
42-
on: tail.on.bind(tail),
43-
unwatch: tail.quit.bind(tail),
39+
watch: () => {
40+
const tail = new TailFile(fp, { startPos: 0, pollFileIntervalMs: 500 })
41+
tail.start()
42+
tail.on("tail_error", (err) => console.error(err))
43+
44+
return {
45+
on: tail.on.bind(tail),
46+
unwatch: tail.quit.bind(tail),
47+
}
48+
},
4449
}),
4550
}
4651
} else {

0 commit comments

Comments
 (0)