@@ -54,7 +54,6 @@ const TerminalPage: FC = () => {
54
54
const [ terminalState , setTerminalState ] = useState <
55
55
"connected" | "disconnected" | "initializing"
56
56
> ( "initializing" ) ;
57
- const [ fitAddon , setFitAddon ] = useState < FitAddon | null > ( null ) ;
58
57
const [ searchParams ] = useSearchParams ( ) ;
59
58
// The reconnection token is a unique token that identifies
60
59
// a terminal session. It's generated by the client to reduce
@@ -125,7 +124,6 @@ const TerminalPage: FC = () => {
125
124
terminal . loadAddon ( new CanvasAddon ( ) ) ;
126
125
}
127
126
const fitAddon = new FitAddon ( ) ;
128
- setFitAddon ( fitAddon ) ;
129
127
terminal . loadAddon ( fitAddon ) ;
130
128
terminal . loadAddon ( new Unicode11Addon ( ) ) ;
131
129
terminal . unicode . activeVersion = "11" ;
@@ -134,13 +132,21 @@ const TerminalPage: FC = () => {
134
132
handleWebLinkRef . current ( uri ) ;
135
133
} ) ,
136
134
) ;
137
- setTerminal ( terminal ) ;
135
+
138
136
terminal . open ( xtermRef . current ) ;
139
- const listener = ( ) => {
140
- // This will trigger a resize event on the terminal.
141
- fitAddon . fit ( ) ;
142
- } ;
137
+
138
+ // We have to fit twice here. It's unknown why, but the first fit will
139
+ // overflow slightly in some scenarios. Applying a second fit resolves this.
140
+ fitAddon . fit ( ) ;
141
+ fitAddon . fit ( ) ;
142
+
143
+ // This will trigger a resize event on the terminal.
144
+ const listener = ( ) => fitAddon . fit ( ) ;
143
145
window . addEventListener ( "resize" , listener ) ;
146
+
147
+ // Terminal is correctly sized and is ready to be used.
148
+ setTerminal ( terminal ) ;
149
+
144
150
return ( ) => {
145
151
window . removeEventListener ( "resize" , listener ) ;
146
152
terminal . dispose ( ) ;
@@ -165,16 +171,10 @@ const TerminalPage: FC = () => {
165
171
166
172
// Hook up the terminal through a web socket.
167
173
useEffect ( ( ) => {
168
- if ( ! terminal || ! fitAddon ) {
174
+ if ( ! terminal ) {
169
175
return ;
170
176
}
171
177
172
- // We have to fit twice here. It's unknown why, but
173
- // the first fit will overflow slightly in some
174
- // scenarios. Applying a second fit resolves this.
175
- fitAddon . fit ( ) ;
176
- fitAddon . fit ( ) ;
177
-
178
178
// The terminal should be cleared on each reconnect
179
179
// because all data is re-rendered from the backend.
180
180
terminal . clear ( ) ;
@@ -289,7 +289,6 @@ const TerminalPage: FC = () => {
289
289
} ;
290
290
} , [
291
291
command ,
292
- fitAddon ,
293
292
proxy . preferredPathAppURL ,
294
293
reconnectionToken ,
295
294
terminal ,
0 commit comments