Skip to content

Commit da4a231

Browse files
committed
Prevent handleWebLink change from recreating terminal
Depending on the timing, handleWebLink was causing the terminal to get recreated. We only need to create the terminal once unless the render type changes. Recreating the terminal was also recreating the web socket pointlessly.
1 parent abd165f commit da4a231

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

site/src/pages/TerminalPage/TerminalPage.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { useDashboard } from "components/Dashboard/DashboardProvider";
1919
import { Region } from "api/typesGenerated";
2020
import { getLatencyColor } from "utils/latency";
2121
import { ProxyStatusLatency } from "components/ProxyStatusLatency/ProxyStatusLatency";
22-
import { portForwardURL } from "utils/portForward";
22+
import { openMaybePortForwardedURL } from "utils/portForward";
2323
import { terminalWebsocketUrl } from "utils/terminal";
2424
import { getMatchingAgentOrFirst } from "utils/workspace";
2525
import {
@@ -99,6 +99,10 @@ const TerminalPage: FC = () => {
9999
},
100100
[workspaceAgent, workspace.data, username, proxy.preferredWildcardHostname],
101101
);
102+
const handleWebLinkRef = useRef(handleWebLink);
103+
useEffect(() => {
104+
handleWebLinkRef.current = handleWebLink;
105+
}, [handleWebLink]);
102106

103107
// Create the terminal!
104108
useEffect(() => {
@@ -127,7 +131,7 @@ const TerminalPage: FC = () => {
127131
terminal.unicode.activeVersion = "11";
128132
terminal.loadAddon(
129133
new WebLinksAddon((_, uri) => {
130-
handleWebLink(uri);
134+
handleWebLinkRef.current(uri);
131135
}),
132136
);
133137
setTerminal(terminal);
@@ -141,7 +145,7 @@ const TerminalPage: FC = () => {
141145
window.removeEventListener("resize", listener);
142146
terminal.dispose();
143147
};
144-
}, [renderer, config.isLoading, xtermRef, handleWebLink]);
148+
}, [renderer, config.isLoading, xtermRef, handleWebLinkRef]);
145149

146150
// Updates the reconnection token into the URL if necessary.
147151
useEffect(() => {

0 commit comments

Comments
 (0)