samdenty / console-feed

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

fix: Throw error when `getArrayLength` receives an empty array #120

Closed jooy2 closed 1 year ago

jooy2 commented 1 year ago

I didn't think of a handling case for empty arrays in my previous PR (#118), I'm a super idiot!

I apologize for the hassle with this ongoing fix. This situation happens frequently and i hope this fix gets reviewed quickly.


This PR resolved the issue in the reproduction below:

How to Reproduce:

For example, suppose you have the following situation:

<Console
    logs={[
      {
        method: 'log',
        id: 'id',
        data: [[], {}, [{}]],
      },
    ]}
/>

If so, you should see the following error in the console below:

TypeError: Cannot read properties of undefined (reading 'toString')

      38 |     return array.length
      39 |   } else {
    > 40 |     const remaining = parseInt(
      41 |       array[array.length - 1].toString().split(REMAINING_KEY)[1]
      42 |     )
      43 | 

      at getArrayLength (src/Component/react-inspector/index.tsx:40:5)
      at CustomInspector.getCustomNode (src/Component/react-inspector/index.tsx:165:27)
      at CustomInspector.nodeRenderer (src/Component/react-inspector/index.tsx:213:31)
      at processChild (node_modules/react-dom/cjs/react-dom-server.node.development.js:3043:14)

Regards,

stackblitz[bot] commented 1 year ago

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.