Skip to content

Commit 68bc81f

Browse files
committed
Try to handle terminal fit a bit better; closes pterodactyl#3121
I'm not sure how to fix this actually, but based on the light reading I did theoretically this should at least prevent it from trying to fit something that doesn't even exist?
1 parent bc87a9c commit 68bc81f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

resources/scripts/components/server/Console.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useMemo, useRef, useState } from 'react';
1+
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
22
import { ITerminalOptions, Terminal } from 'xterm';
33
import { FitAddon } from 'xterm-addon-fit';
44
import { SearchAddon } from 'xterm-addon-search';
@@ -135,11 +135,12 @@ export default () => {
135135

136136
useEffect(() => {
137137
if (connected && ref.current && !terminal.element) {
138-
terminal.open(ref.current);
139138
terminal.loadAddon(fitAddon);
140139
terminal.loadAddon(searchAddon);
141140
terminal.loadAddon(searchBar);
142141
terminal.loadAddon(webLinksAddon);
142+
143+
terminal.open(ref.current);
143144
fitAddon.fit();
144145

145146
// Add support for capturing keys
@@ -159,11 +160,11 @@ export default () => {
159160
}
160161
}, [ terminal, connected ]);
161162

162-
const fit = debounce(() => {
163-
fitAddon.fit();
164-
}, 100);
165-
166-
useEventListener('resize', () => fit());
163+
useEventListener('resize', debounce(() => {
164+
if (terminal.element) {
165+
fitAddon.fit();
166+
}
167+
}, 100));
167168

168169
useEffect(() => {
169170
const listeners: Record<string, (s: string) => void> = {

0 commit comments

Comments
 (0)