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

Passing elements wrapped with the short syntax of React.Fragment into a component as its children may cause a page to crash #7391

Closed
6 of 7 tasks
ghost opened this issue May 11, 2022 · 1 comment · Fixed by #7392
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: markdown Related to Markdown parsing or syntax

Comments

@ghost
Copy link

ghost commented May 11, 2022

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

For example, if I have a component like this:

const TestComponent = ({ children }) => {
  const [a, b] = children;

  return (
    <div>
      <div>{a}</div>
      <div>{b}</div>
    </div>
  );
};

Then I import this component in a doc and use the component like this:

import TestComponent from "../src/components/TestComponent"

<TestComponent>

<>a</>

<>b</>

</TestComponent>

I'll get this error:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of `MDXContent`.

Reproducible demo

https://github.com/awesomeraccoons/docusaurus/blob/main/docs/intro.md?plain=1

Steps to reproduce

  1. Create a component that takes in a children prop and renders the elements in the children.
  2. Import this component in a doc and pass elements wrapped with <></> into an instance of it.

Expected behavior

The page renders correctly as if the <></> was written in the form of <React.Fragment></React.Fragment>.

Actual behavior

The page crashes with the following error:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of `MDXContent`.

Your environment

  • Public source code: https://github.com/awesomeraccoons/docusaurus
  • Public site URL: N/A
  • Docusaurus version used: 2.0.0-beta.20
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): Chrome 101.0.4951.54
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): macOS 12.3.1

Self-service

  • I'd be willing to fix this bug myself.
@ghost ghost added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels May 11, 2022
@Josh-Cena Josh-Cena removed the status: needs triage This issue has not been triaged by maintainers label May 11, 2022
@Josh-Cena
Copy link
Collaborator

Josh-Cena commented May 11, 2022

For some reason, the mdx.Fragment in fragment JSX pragma is not present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: markdown Related to Markdown parsing or syntax
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant