Skip to content

Commit deaf049

Browse files
christianalfoniCompuIves
authored andcommitted
Batch messages to terminal before terminal initialized (codesandbox#2773)
* Batch messages to terminal before terminal initialized * Update packages/app/src/app/components/Preview/DevTools/Terminal/index.tsx * Update packages/app/src/app/components/Preview/DevTools/Terminal/index.tsx * Update packages/app/src/app/components/Preview/DevTools/Terminal/index.tsx * Update packages/app/src/app/components/Preview/DevTools/Terminal/index.tsx
1 parent e52021f commit deaf049

File tree

1 file changed

+13
-6
lines changed
  • packages/app/src/app/components/Preview/DevTools/Terminal

1 file changed

+13
-6
lines changed

packages/app/src/app/components/Preview/DevTools/Terminal/index.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1+
import './styles.css';
2+
3+
import { listen } from 'codesandbox-api';
14
import React from 'react';
5+
import PlusIcon from 'react-icons/lib/md/add';
26
import { withTheme } from 'styled-components';
3-
import { listen } from 'codesandbox-api';
4-
57
import uuid from 'uuid';
6-
import PlusIcon from 'react-icons/lib/md/add';
7-
8-
import './styles.css';
98

109
import { Shell } from './Shell';
1110
import { TerminalComponent } from './Shell/Term';
1211
import { ShellTabs } from './ShellTabs';
13-
1412
import { ShellT, TerminalWithFit } from './types';
1513
import { DevToolProps } from '..';
1614

@@ -34,6 +32,7 @@ class DevToolTerminal extends React.Component<
3432
};
3533

3634
term: TerminalWithFit;
35+
messageQueue: any[];
3736
listener: () => void;
3837
node?: HTMLElement;
3938
timeout?: number;
@@ -46,9 +45,17 @@ class DevToolTerminal extends React.Component<
4645

4746
setTerminal = (terminal: TerminalWithFit) => {
4847
this.term = terminal;
48+
49+
this.messageQueue.forEach(this.handleMessage);
50+
this.messageQueue.length = 0;
4951
};
5052

5153
handleMessage = (data: any) => {
54+
if (!this.term) {
55+
this.messageQueue.push(data);
56+
return;
57+
}
58+
5259
if (data.type === 'terminal:message') {
5360
this.term.write(data.data);
5461

0 commit comments

Comments
 (0)