Skip to content

Commit e2e07b0

Browse files
authored
fix: revert to canvas renderer for xterm (coder#8138)
The default changed from canvas to DOM in the last update. The canvas renderer resolves line spacing issues and has better performance, as well as bringing us back to the previous status quo. In the new version the canvas is enabled via an addon.
1 parent b4751c7 commit e2e07b0

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

site/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"vite": "4.3.9",
9595
"xstate": "4.37.2",
9696
"xterm": "5.1.0",
97+
"xterm-addon-canvas": "0.4.0",
9798
"xterm-addon-fit": "0.7.0",
9899
"xterm-addon-web-links": "0.8.0",
99100
"yup": "0.32.11"

site/src/AppRouter.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export const AppRouter: FC = () => {
317317
{/* Terminal and CLI auth pages don't have the dashboard layout */}
318318
<Route
319319
path="/:username/:workspace/terminal"
320-
element={<TerminalPage />}
320+
element={<TerminalPage renderer="canvas" />}
321321
/>
322322
<Route path="cli-auth" element={<CliAuthenticationPage />} />
323323
</Route>

site/src/pages/TerminalPage/TerminalPage.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Object.defineProperty(window, "TextEncoder", {
3838
const renderTerminal = async (
3939
route = `/${MockUser.username}/${MockWorkspace.name}/terminal`,
4040
) => {
41-
const utils = renderWithAuth(<TerminalPage />, {
41+
const utils = renderWithAuth(<TerminalPage renderer="dom" />, {
4242
route,
4343
path: "/:username/:workspace/terminal",
4444
})

site/src/pages/TerminalPage/TerminalPage.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useNavigate, useParams, useSearchParams } from "react-router-dom"
88
import { colors } from "theme/colors"
99
import { v4 as uuidv4 } from "uuid"
1010
import * as XTerm from "xterm"
11+
import { CanvasAddon } from "xterm-addon-canvas"
1112
import { FitAddon } from "xterm-addon-fit"
1213
import { WebLinksAddon } from "xterm-addon-web-links"
1314
import "xterm/css/xterm.css"
@@ -69,7 +70,11 @@ const useTerminalWarning = ({
6970
}
7071
}
7172

72-
const TerminalPage: FC = () => {
73+
type TerminalPageProps = React.PropsWithChildren<{
74+
renderer: "canvas" | "dom"
75+
}>
76+
77+
const TerminalPage: FC<TerminalPageProps> = ({ renderer }) => {
7378
const navigate = useNavigate()
7479
const styles = useStyles()
7580
const { proxy } = useProxy()
@@ -194,6 +199,10 @@ const TerminalPage: FC = () => {
194199
background: colors.gray[16],
195200
},
196201
})
202+
// DOM is the default renderer.
203+
if (renderer === "canvas") {
204+
terminal.loadAddon(new CanvasAddon())
205+
}
197206
const fitAddon = new FitAddon()
198207
setFitAddon(fitAddon)
199208
terminal.loadAddon(fitAddon)
@@ -230,7 +239,7 @@ const TerminalPage: FC = () => {
230239
window.removeEventListener("resize", listener)
231240
terminal.dispose()
232241
}
233-
}, [sendEvent, xtermRef, handleWebLink])
242+
}, [renderer, sendEvent, xtermRef, handleWebLink])
234243

235244
// Triggers the initial terminal connection using
236245
// the reconnection token and workspace name found

site/yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -12173,6 +12173,11 @@ xtend@^4.0.0, xtend@~4.0.1:
1217312173
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
1217412174
integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==
1217512175

12176+
xterm-addon-canvas@0.4.0:
12177+
version "0.4.0"
12178+
resolved "https://registry.yarnpkg.com/xterm-addon-canvas/-/xterm-addon-canvas-0.4.0.tgz#a6ee6a56deb0c495fcef29afe6d94b7119a0f334"
12179+
integrity sha512-iTC8CdjX9+hGX7jiEuiDMXzHsY/FKJdVnbjep5xjRXNu7RKOk15xuecIkJ7HZORqMVPpr4DGS3jyd9XUoBuxqw==
12180+
1217612181
xterm-addon-fit@0.7.0:
1217712182
version "0.7.0"
1217812183
resolved "https://registry.yarnpkg.com/xterm-addon-fit/-/xterm-addon-fit-0.7.0.tgz#b8ade6d96e63b47443862088f6670b49fb752c6a"

0 commit comments

Comments
 (0)