Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Astro MDX fails to render framework components and components defined with MDX file, when explicit null or undefined prop passed in #10575

Closed
1 task done
duanwilliam opened this issue Mar 27, 2024 · 1 comment · Fixed by #10584
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@duanwilliam
Copy link
Contributor

duanwilliam commented Mar 27, 2024

Astro Info

(from stackblitz environment)

Astro                    v4.5.10
Node                     v18.18.0
System                   Linux (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             @astrojs/mdx

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

If a framework component is used within an MDX file, and one of its props gets passed in an explicit undefined or null, Astro crashes with an error trying to render the component.
This issue also occurs for components defined within the MDX file.

e.g.

import A from 'foo.jsx'

export function B() { return <div /> }

{/* both of these cause an error */}
<A foo={undefined} />
<B bar={undefined} />

The problematic line is

for (const [key, value] of Object.entries(props)) {
if (value['$$slot']) {

in these cases,

  • vnode is an object, so renderJSX delegates to renderJSXNode (this seems to be true of all the jsx inside an mdx file?)
  • vnode['astro:jsx'] is true (i.e. it is in fact a vnode)
  • vnode.type is the component, i.e. a function
  • vnode.type does not have isAstroComponentFactory set
  • there is no truthy server:root prop

which leads to aforementioned line being called, resulting in attempting to do a property access on null/undefined which results in an error.

What's the expected result?

Component renders properly.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-mbbqqu?file=src%2Fpages%2Fa.mdx

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Mar 27, 2024
@matthewp
Copy link
Contributor

Yes, please do send a PR, thanks!

@matthewp matthewp added - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs triage Issue needs to be triaged labels Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants