react-console icon indicating copy to clipboard operation
react-console copied to clipboard

Runtime error is thrown if first command is triggered outside of the component via the public log method

Open mitk0936 opened this issue 5 years ago • 6 comments

https://github.com/autochthe/react-console/blob/0d5d0834b2131cc86f1fa6342fe3d52130c636ad/src/react-console.tsx#L180

In the case when this.state.log is empty array, JS runtime error is thrown. "Uncaught TypeError: Cannot read property 'message' of undefined"

mitk0936 avatar Dec 24 '18 15:12 mitk0936

This is because the log method adds messages to an associated command. At present, if you call log without a command, there is no sensible place to record the message. What is your use case for this functionality? This should only occur before a command is entered. Are you able to use the welcomeMessage for your purpose?

astralarya avatar Jan 07 '19 18:01 astralarya

#8

astralarya avatar Jan 07 '19 18:01 astralarya

It is reproducible when there is a welcome message as well. My scenario is that in some cases the first command to the console is triggered from outside. So why not to add the message at index log[0] when this.state.log.length is 0?

mitk0936 avatar Jan 08 '19 08:01 mitk0936

I didn't mean to ask if the big was reproducible but if you were l could use the welcome message for your use case. This problem would necessitate a rewrite of the log functionality, so this would only be a temporary workaround.

astralarya avatar Jan 08 '19 12:01 astralarya

I'll implement your suggestion later this week, but that too isn't really a proper long term solution.

astralarya avatar Jan 08 '19 12:01 astralarya

Will this be fixed? I need to be able to send messages to the console without a command being received first - the main purpose of the console in my app is to display information. The welcome message won't work for this.

Merlin04 avatar Sep 18 '20 18:09 Merlin04