Skip to content

fix: prevent unnecessary wrapping of single line jsx elements #2183

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

Merged

Conversation

ThomasRoest
Copy link
Collaborator

When having a single line statement with an import statement everything works as expected.

import * as React from "react";
<ReactComponent />;

However if you remove the import statement, a semicolon ; appears in the output. We no longer need the explicit import statements as this can be configured globally, and we have an eslint rule requiring us to close every js statement with a semicolon.

<ReactComponent />;

This happens because of the fix/changes done in this issue: #842, which causes every statement starting with JSX to be wrapped in a Fragment. This will cause the semicolon to be added inside the Fragment, and cause it to be rendered.

This change causes the examples to only be wrapped in a Fragment if multiple jsx statements are returned on root level of the example by checking for the error before wrapping.

When having a single line statement with an import statement everything works as expected.

```jsx
    import * as React from "react";
    <ReactComponent />;
```

However if you remove the import statement, a semicolon `;` appears in the output. We no longer need the explicit import statements as this can be configured globally, and we have an eslint rule requiring us to close every js statement with a semicolon.

```jsx
    <ReactComponent />;
```

This happens because of the fix/changes done in this issue: styleguidist#842, which causes every statement starting with JSX to be wrapped in a Fragment. This will cause the semicolon to be added inside the Fragment, and cause it to be rendered.

This change causes the examples to only be wrapped in a Fragment if multiple jsx statements are returned on root level of the example by checking for the error before wrapping.
@ThomasRoest ThomasRoest merged commit c223f9a into styleguidist:master Jan 7, 2025
9 checks passed
@ThomasRoest ThomasRoest deleted the fix_unnecessary_jsx_wrapping branch January 7, 2025 10:43
Copy link

github-actions bot commented Jan 7, 2025

🎉 This PR is included in version 13.1.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant