Skip to content

Commit 57c9d88

Browse files
authored
chore(site): remove terminal xservice (#10234)
* Remove terminalXService This is a prelude to the change I actually want to make, which is to send the size of the terminal on the web socket URL after we do a fit. I have found xstate so confusing that it was easier to just rewrite it. * Fix hanging tests I am not really sure what ws.connected is doing but it seems to somehow block updates. Something to do with `act()` maybe? Basically, the useEffect creating the terminal never updates once the config query finishes, so the web socket is never created, and the test hangs forever. It might have been working before only because the web socket was created using xstate rather than useEffect and once it connected it would unblock and React could update again but this is just a guess. * Ignore other config changes The terminal only cares about the renderer specifically, no need to recreate the terminal if something else changes. * Break out port forward URL open to util Felt like this could be broken out to reduce the component size. Also trying to figure out why it is causing the terminal to create multiple times. * Prevent handleWebLink change from recreating terminal Depending on the timing, handleWebLink was causing the terminal to get recreated. We only need to create the terminal once unless the render type changes. Recreating the terminal was also recreating the web socket pointlessly.
1 parent 5ebb702 commit 57c9d88

File tree

6 files changed

+264
-509
lines changed

6 files changed

+264
-509
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,19 @@ describe("TerminalPage", () => {
127127
const { container } = await renderTerminal();
128128

129129
// Then
130-
await ws.connected;
130+
// Ideally we could use ws.connected but that seems to pause React updates.
131+
// For now, wait for the initial resize message instead.
132+
await ws.nextMessage;
131133
ws.send(text);
132134
await expectTerminalText(container, text);
133135
ws.close();
134136
});
135137

138+
// Ideally we could just pass the correct size in the web socket URL without
139+
// having to resize separately afterward (and then we could delete also this
140+
// test), but we need the initial resize message to have something to wait for
141+
// in the other tests since ws.connected appears to pause React updates. So
142+
// for now the initial resize message (and this test) are here to stay.
136143
it("resizes on connect", async () => {
137144
// Given
138145
const ws = new WS(
@@ -143,7 +150,6 @@ describe("TerminalPage", () => {
143150
await renderTerminal();
144151

145152
// Then
146-
await ws.connected;
147153
const msg = await ws.nextMessage;
148154
const req = JSON.parse(new TextDecoder().decode(msg as Uint8Array));
149155
expect(req.height).toBeGreaterThan(0);
@@ -164,7 +170,9 @@ describe("TerminalPage", () => {
164170
);
165171

166172
// Then
167-
await ws.connected;
173+
// Ideally we could use ws.connected but that seems to pause React updates.
174+
// For now, wait for the initial resize message instead.
175+
await ws.nextMessage;
168176
ws.send(text);
169177
await expectTerminalText(container, text);
170178
ws.close();

0 commit comments

Comments
 (0)