Skip to content

Commit 15d3f58

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 e779917 commit 15d3f58

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

site/src/pages/TerminalPage/TerminalPage.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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)