Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@
"humps": "CompuIves/humps",
"ignore": "^5.1.4",
"immer": "^3.2.0",
"immutability-helper": "^2.6.6",
"instantsearch.css": "^7.1.0",
"is-url": "^1.2.2",
"jest-circus": "^22.1.4",
Expand Down
47 changes: 24 additions & 23 deletions packages/app/src/app/components/Preview/DevTools/Console/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Select from '@codesandbox/common/lib/components/Select';
import theme from '@codesandbox/common/lib/theme';
import { listen, dispatch } from 'codesandbox-api';
import { Decode, Console as ConsoleFeed } from 'console-feed';
import update from 'immutability-helper';
import immer from 'immer';
import { debounce } from 'lodash-es';
import React from 'react';
import ClearIcon from 'react-icons/lib/md/block';
Expand All @@ -27,17 +27,27 @@ const StyledClearIcon = styled(ClearIcon)`
font-size: 0.8em;
`;

class ConsoleComponent extends React.Component<StyledProps> {
type State = {
messages: any[];
filter: Array<'info' | 'log' | 'warn'>;
searchKeywords: string;
};

/**
* Max amount of messages that we show in the console
*/
const MAX_MESSAGE_COUNT = 500;

class ConsoleComponent extends React.PureComponent<StyledProps, State> {
state = {
messages: [],
initialClear: true,
filter: [],
searchKeywords: '',
};

listener;

constructor(props) {
constructor(props: StyledProps) {
super(props);

this.scrollToBottom = debounce(this.scrollToBottom, 1 / 60);
Expand Down Expand Up @@ -75,13 +85,8 @@ class ConsoleComponent extends React.Component<StyledProps> {
break;
}
case 'clear-console': {
if (this.state.initialClear) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized we don't use this anymore, and prevents first clear on the console.

this.setState({
initialClear: false,
});
} else {
this.clearConsole();
}
this.clearConsole();

break;
}
case 'eval-result': {
Expand Down Expand Up @@ -147,22 +152,18 @@ class ConsoleComponent extends React.Component<StyledProps> {
}

this.setState(state =>
update(state, {
messages: {
$push: [
{
method,
data,
},
],
},
immer(state, draft => {
draft.messages.push({ method, data });
draft.messages = draft.messages.slice(
Math.max(0, draft.messages.length - MAX_MESSAGE_COUNT)
);
})
);
}

list;
list: HTMLDivElement | undefined;

UNSAFE_componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps: StyledProps) {
if (nextProps.sandboxId !== this.props.sandboxId) {
this.clearConsole(true);
}
Expand Down Expand Up @@ -273,7 +274,7 @@ const ConsoleFilterSelect = props => {
return (
<Select
style={{
fontFamily: 'Roboto',
fontFamily: 'Inter',
fontWeight: 600,
fontSize: '0.875rem',
height: 22,
Expand Down
37 changes: 21 additions & 16 deletions packages/app/src/app/components/Preview/DevTools/Tests/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,12 @@ class Tests extends React.Component<DevToolProps, State> {
* Every setState call will have to go through this, otherwise we get race conditions
* where the underlying state has changed, but the draftState didn't change.
*/
setStateDebounced = (setStateFunc, time = 200) => {
setStateDelayedFlush = (
setStateFunc:
| Partial<State>
| ((state: State, props: DevToolProps) => Partial<State>),
time = 200
) => {
const draftState = this.draftState || this.state;

const newState =
Expand Down Expand Up @@ -217,7 +222,7 @@ class Tests extends React.Component<DevToolProps, State> {

UNSAFE_componentWillReceiveProps(nextProps: DevToolProps) {
if (nextProps.sandboxId !== this.props.sandboxId) {
this.setStateDebounced(
this.setStateDelayedFlush(
{
files: {},
selectedFilePath: null,
Expand All @@ -233,7 +238,7 @@ class Tests extends React.Component<DevToolProps, State> {
}

selectFile = (file: File) => {
this.setStateDebounced(
this.setStateDelayedFlush(
state => ({
selectedFilePath:
file.fileName === state.selectedFilePath ? null : file.fileName,
Expand All @@ -243,7 +248,7 @@ class Tests extends React.Component<DevToolProps, State> {
};

toggleFileExpansion = (file: File) => {
this.setStateDebounced(
this.setStateDelayedFlush(
oldState =>
immer(oldState, state => {
state.fileExpansionState[file.fileName] = !state.fileExpansionState[
Expand Down Expand Up @@ -278,7 +283,7 @@ class Tests extends React.Component<DevToolProps, State> {
if (this.props.updateStatus) {
this.props.updateStatus('clear');
}
this.setStateDebounced(INITIAL_STATE, 0);
this.setStateDelayedFlush(INITIAL_STATE, 0);
break;
}
case 'test_count': {
Expand All @@ -294,7 +299,7 @@ class Tests extends React.Component<DevToolProps, State> {
if (this.props.updateStatus) {
this.props.updateStatus('clear');
}
this.setStateDebounced(
this.setStateDelayedFlush(
{
running: true,
},
Expand All @@ -303,7 +308,7 @@ class Tests extends React.Component<DevToolProps, State> {
break;
}
case messages.TOTAL_TEST_END: {
this.setStateDebounced(
this.setStateDelayedFlush(
{
running: false,
},
Expand Down Expand Up @@ -333,7 +338,7 @@ class Tests extends React.Component<DevToolProps, State> {
}

case messages.ADD_FILE: {
this.setStateDebounced(oldState =>
this.setStateDelayedFlush(oldState =>
immer(oldState, state => {
state.files[data.path] = {
tests: {},
Expand All @@ -346,7 +351,7 @@ class Tests extends React.Component<DevToolProps, State> {
break;
}
case 'remove_file': {
this.setStateDebounced(oldState =>
this.setStateDelayedFlush(oldState =>
immer(oldState, state => {
if (state.files[data.path]) {
delete state.files[data.path];
Expand All @@ -358,7 +363,7 @@ class Tests extends React.Component<DevToolProps, State> {
break;
}
case messages.FILE_ERROR: {
this.setStateDebounced(oldState =>
this.setStateDelayedFlush(oldState =>
immer(oldState, state => {
if (state.files[data.path]) {
state.files[data.path].fileError = data.error;
Expand All @@ -378,7 +383,7 @@ class Tests extends React.Component<DevToolProps, State> {
case messages.ADD_TEST: {
const testName = [...this.currentDescribeBlocks, data.testName];

this.setStateDebounced(oldState =>
this.setStateDelayedFlush(oldState =>
immer(oldState, state => {
if (!state.files[data.path]) {
state.files[data.path] = {
Expand All @@ -404,7 +409,7 @@ class Tests extends React.Component<DevToolProps, State> {
const { test } = data;
const testName = [...test.blocks, test.name];

this.setStateDebounced(oldState =>
this.setStateDelayedFlush(oldState =>
immer(oldState, state => {
if (!state.files[test.path]) {
state.files[test.path] = {
Expand Down Expand Up @@ -435,7 +440,7 @@ class Tests extends React.Component<DevToolProps, State> {
const { test } = data;
const testName = [...test.blocks, test.name];

this.setStateDebounced(oldState =>
this.setStateDelayedFlush(oldState =>
immer(oldState, state => {
if (!state.files[test.path]) {
return;
Expand Down Expand Up @@ -524,22 +529,22 @@ class Tests extends React.Component<DevToolProps, State> {
};

toggleWatching = () => {
this.setStateDebounced(state => ({ watching: !state.watching }), 0);
this.setStateDelayedFlush(state => ({ watching: !state.watching }), 0);
dispatch({
type: 'set-test-watching',
watching: !this.state.watching,
});
};

runAllTests = () => {
this.setStateDebounced({ files: {} }, 0);
this.setStateDelayedFlush({ files: {} }, 0);
dispatch({
type: 'run-all-tests',
});
};

runTests = (file: File) => {
this.setStateDebounced(
this.setStateDelayedFlush(
oldState =>
immer(oldState, state => {
if (state.files[file.fileName]) {
Expand Down
Loading