Skip to content

Rendering <Content /> fails for MDX file containing <Fragment> #5519

@delucis

Description

@delucis

What version of astro are you using?

1.6.12

Are you using an SSR adapter? If so, which one?

n/a

What package manager are you using?

npm

What operating system are you using?

macOS / Stackblitz

Describe the Bug

(Ran into this bug as part of migrating docs to MDX and it’s a bit of blocker given how much we use <Fragment> to pass content to slots.)

  1. MDX supports using <Fragment>, which can be useful for example to pass stuff to a named slot:

    <Component>
      <Fragment slot="box">Box content</Fragment>
    </Component>

    This renders fine for an MDX page, e.g. src/pages/index.mdx.

  2. If you import (or glob) the same page and use it’s <Content /> component however:

    ---
    import { Content } from './index.mdx';
    ---
    <Content />

    Astro will throw an error:

    Expected component `Fragment` to be defined: you likely forgot to import, pass, or provide it.
    

I guess somewhere <Fragment> support is being wired up when a page is rendered but that same wiring is missing for the <Content /> render.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-zq6zwz?file=src/pages/index.mdx

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions