Skip to content

Commit

Permalink
Fix XTerm.js crash on undefined dimensions
Browse files Browse the repository at this point in the history
During terminal initialization, the `_renderService` or its
`.dimensions` attribute may not yet be defined. Exit the resizing
function in this case instead of crashing with a `TypeError`.

Add a reference to the upstream issue about this internal API hackery.
  • Loading branch information
martinpitt committed Jan 26, 2025
1 parent 56441f0 commit deae997
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ContainerLogs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ class ContainerLogs extends React.Component {
}

resize(width) {
if (!this.term?._core?._renderService?.dimensions)
return;
// 24 PF padding * 4
// 3 line border
// 21 inner padding of xterm.js
// xterm.js scrollbar 20
const padding = 24 * 4 + 3 + 21 + 20;
// missing API: https://github.com/xtermjs/xterm.js/issues/702
const realWidth = this.view._core._renderService.dimensions.css.cell.width;
const cols = Math.floor((width - padding) / realWidth);
this.view.resize(cols, 24);
Expand Down
3 changes: 3 additions & 0 deletions src/ContainerTerminal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,14 @@ class ContainerTerminal extends React.Component {
}

resize(width) {
if (!this.term?._core?._renderService?.dimensions)
return;
// 24 PF padding * 4
// 3 line border
// 21 inner padding of xterm.js
// xterm.js scrollbar 20
const padding = 24 * 4 + 3 + 21 + 20;
// missing API: https://github.com/xtermjs/xterm.js/issues/702
const realWidth = this.term._core._renderService.dimensions.css.cell.width;
const cols = Math.floor((width - padding) / realWidth);
this.term.resize(cols, 24);
Expand Down

0 comments on commit deae997

Please sign in to comment.