Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
fix: add custom unique id to each console message
Browse files Browse the repository at this point in the history
  • Loading branch information
dungwinux authored and arjunguha committed Apr 24, 2021
1 parent 5bb6ba2 commit d07b2da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
13 changes: 13 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"get-own-enumerable-property-symbols": "^3.0.0",
"lodash": "^4.17.19",
"monaco-editor": "^0.13.1",
"nanoid": "^3.1.22",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-google-login": "^3.2.1",
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/OutputPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as monacoEditor from 'monaco-editor';
import RightArrowIcon from '@material-ui/icons/KeyboardArrowRight';

import { Console } from 'console-feed';
import { nanoid } from 'nanoid';
import { inspectorTheme } from './static/styles/consoleStyle';
import 'static/styles/Scrollbar.css';
import { Sandbox } from './sandbox';
Expand Down Expand Up @@ -153,7 +154,12 @@ class OutputPanel extends React.Component<Props, State> {
/** Appends a message to the log. Bounds scrollback to 100 items. */
appendLogMessage(message: Message | { method: 'command' | 'result' | 'error', data: any }) {
this.setState((prevState) => {
let newLog = [...prevState.logs, message as Message];
const messageView = message as Message;
/** Get a unique ID for each message. Solve React rendering issue */
/** Ignore is needed due to the fact that the maintainer of console-feed ignore id in Message defintion */
// @ts-ignore
messageView.id = nanoid(7);
let newLog = [...prevState.logs, messageView];
if (newLog.length > 100) {
newLog = newLog.slice(newLog.length - 100);
}
Expand Down

0 comments on commit d07b2da

Please sign in to comment.