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

🐛 BUG: React children surrounded by empty <p> tags #3319

Closed
1 task
pReya opened this issue May 9, 2022 · 3 comments · Fixed by #3410
Closed
1 task

🐛 BUG: React children surrounded by empty <p> tags #3319

pReya opened this issue May 9, 2022 · 3 comments · Fixed by #3410
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: markdown Related to Markdown (scope)

Comments

@pReya
Copy link
Contributor

pReya commented May 9, 2022

What version of astro are you using?

1.0.0-beta.27

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

None

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

I have the following, very simple React component:

const TextBlock = ({
  title,
  children,
  noPadding = false,
}) => {
  return (
    <div
      className={`${
        noPadding ? "" : "md:px-2 lg:px-4"
      } flex-1 prose prose-headings:font-grotesk`}
    >
      <h3>{title}</h3>
      <p>{children}</p>
    </div>
  );
};

I am using this component in the following way inside a page.md page:

  <TextBlock title="Eintritt/Hinweise" noPadding>
    <ul class="not-prose">
      <li>Eintritt frei</li>
      <li>Anmeldung erforderlich</li>
      <li>Teilnehmerzahl begrenzt</li>
    </ul>
  </TextBlock>

However, the actual children (which is the <ul> element) are not being rendered correctly inside the {children} variable inside the React component. Instead, they are surrounded with empty <p></p> tags instead of being INSIDE the <p></p> tags. Here is the actual DOM output:

<div class="flex-1 prose prose-headings:font-grotesk">
    <h3>Eintritt/Hinweise</h3>
    <p></p>
    <ul class="not-prose">
      <li>Eintritt frei</li>
      <li>Anmeldung erforderlich</li>
      <li>Teilnehmerzahl begrenzt</li>
    </ul>
    <p></p>
</div>

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-b7imzh?file=src/pages/index.astro

Participation

  • I am willing to submit a pull request for this issue.
@pReya pReya changed the title 🐛 BUG: React children not rendered in the correct position 🐛 BUG: React children surrounded by empty <p> tags May 9, 2022
@natemoo-re natemoo-re added the feat: markdown Related to Markdown (scope) label May 10, 2022
@natemoo-re natemoo-re added - P3: minor bug An edge case that only affects very specific usage (priority) s2-medium and removed bb:investigate labels May 10, 2022
@natemoo-re
Copy link
Member

Sorry for the frustration! This is definitely an issue with our Markdown rendering, likely coming from the default either remark or rehype behavior.

If possible, we should be removing empty <p></p> tags.

@natemoo-re natemoo-re linked a pull request May 19, 2022 that will close this issue
natemoo-re added a commit that referenced this issue May 24, 2022
* feat: use internal MDX tooling for markdown + components

* fix: improve MD + component tests

* chore: add changeset

* fix: make tsc happy

* fix(#3319): add regression test for component children

* fix(markdown): support HTML comments in markdown

* fix(#2474): ensure namespaced components are properly handled in markdown pages

* fix(#3220): ensure html in markdown pages does not have extra surrounding space

* fix(#3264): ensure that remark files pass in file information

* fix(#3254): enable experimentalStaticExtraction for `.md` pages

* fix: revert parsing change

* fix: remove `markdown.mode` option
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this issue Feb 3, 2023
* feat: use internal MDX tooling for markdown + components

* fix: improve MD + component tests

* chore: add changeset

* fix: make tsc happy

* fix(withastro#3319): add regression test for component children

* fix(markdown): support HTML comments in markdown

* fix(withastro#2474): ensure namespaced components are properly handled in markdown pages

* fix(withastro#3220): ensure html in markdown pages does not have extra surrounding space

* fix(withastro#3264): ensure that remark files pass in file information

* fix(withastro#3254): enable experimentalStaticExtraction for `.md` pages

* fix: revert parsing change

* fix: remove `markdown.mode` option
@Msteimel
Copy link

Msteimel commented Jun 9, 2023

I have recently run into the same (or at least very similar) issue using an .mdx file from a content folder.

When the element tags are on their own line, they cause empty p tags to render

Code:

<p>Deserunt duis commodo commodo nulla id adipisicing aliquip.</p>
<p>
  Deserunt duis commodo commodo nulla id adipisicing aliquip.Voluptate ea
  reprehenderit proident culpa pariatur commodo laboris anim culpa culpa laboris
  do ad est laboris.
</p>

What renders

<p>Deserunt duis commodo commodo nulla id adipisicing aliquip.</p>
<p></p>
<p>Deserunt duis commodo commodo nulla id adipisicing aliquip.Voluptate ea
reprehenderit proident culpa pariatur commodo laboris anim culpa culpa
laboris do ad est laboris.</p>
<p></p>

@mleister97
Copy link

Same issue here... so many empty paragraph elements

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) feat: markdown Related to Markdown (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants