samdenty / console-feed

Captures console.log's into a React Component 🔥
https://stackblitz.com/~/github.com/samdenty/console-feed
MIT License
662 stars 110 forks source link

`Decode` causes lost `data` if there is no `"__console_feed_remaining__0"` entry #125

Open lindapaiste opened 1 year ago

lindapaiste commented 1 year ago

We've had some problems over on the p5 Web Editor with upgrading from ^3.2.0 to ^3.5.0.

I've traced it back to the Decode function and the changes that were made there to support the limit option. https://github.com/samdenty/console-feed/blob/19a2c05f59e0f51ac32862d1a5c5d61f63a22c9b/src/Transform/index.ts#L18-L23

The problem is that sometimes the messages which we are decoding do not have a __console_feed_remaining__0 entry at the end of the data array. This could be due to improper usage on our end. But the Decode function will always remove the last element of the data array regardless of what the element actually is. The code would be safer if it validated the entry before removing it, using code similar to this: https://github.com/samdenty/console-feed/blob/19a2c05f59e0f51ac32862d1a5c5d61f63a22c9b/src/Component/react-inspector/index.tsx#L199-L202