bright icon indicating copy to clipboard operation
bright copied to clipboard

Using ReactNode as child of <Code> breaks the component

Open alfonsusac opened this issue 1 year ago • 1 comments

Usage:

<Code>
  <div>asd</div>
</Code>

Tested in Next.js 13.4.14 Server Component

Errors:

- error TypeError: Cannot read properties of undefined (reading 'children')
    at eval (../bright/lib/src/index.tsx:179:53)
    at Array.map (<anonymous>)
    at parseChildren (../bright/lib/src/index.tsx:176:88)
    at Code (../bright/lib/src/index.tsx:34:31)
    at stringify (<anonymous>)
digest: "1512087678"
  203 |       const codeProps = c.props?.children?.props
  204 |       return {
> 205 |         code: trimTrailingNewline(codeProps.children),
      |                                            ^
  206 |         ...getLanguageAndTitle(codeProps.className),
  207 |       }
  208 |     })

this error is using bright/src not bright/dist

alfonsusac avatar Aug 14 '23 06:08 alfonsusac

Im curioust to know, what this part of the code is meant to be used for? https://github.com/code-hike/bright/blob/bb61dada0f95cd077ebeda37722a52095757f6d0/lib/src/index.tsx#L198 I know the first guard is for Markdown, and the third one is for plain texts but what is the second one for?

alfonsusac avatar Aug 14 '23 06:08 alfonsusac