From 68bc81f2f123437aad6f16652466c775db57d6fe Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Wed, 3 Mar 2021 19:44:06 -0800 Subject: [PATCH] Try to handle terminal fit a bit better; closes #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? --- resources/scripts/components/server/Console.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/resources/scripts/components/server/Console.tsx b/resources/scripts/components/server/Console.tsx index 4301cd97..281e8152 100644 --- a/resources/scripts/components/server/Console.tsx +++ b/resources/scripts/components/server/Console.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useMemo, useRef, useState } from 'react'; +import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'; import { ITerminalOptions, Terminal } from 'xterm'; import { FitAddon } from 'xterm-addon-fit'; import { SearchAddon } from 'xterm-addon-search'; @@ -135,11 +135,12 @@ export default () => { useEffect(() => { if (connected && ref.current && !terminal.element) { - terminal.open(ref.current); terminal.loadAddon(fitAddon); terminal.loadAddon(searchAddon); terminal.loadAddon(searchBar); terminal.loadAddon(webLinksAddon); + + terminal.open(ref.current); fitAddon.fit(); // Add support for capturing keys @@ -159,11 +160,11 @@ export default () => { } }, [ terminal, connected ]); - const fit = debounce(() => { - fitAddon.fit(); - }, 100); - - useEventListener('resize', () => fit()); + useEventListener('resize', debounce(() => { + if (terminal.element) { + fitAddon.fit(); + } + }, 100)); useEffect(() => { const listeners: Record void> = {