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

🚀 Fix: Prevent <pre> from being Wrapped in <p> to Resolve Hydration Error (#770) #832

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SaiShanmukkha
Copy link

Description

This PR resolves the issue where <pre> elements are incorrectly nested inside <p>, which leads to a React hydration error. The error occurs when rendering Markdown content, specifically when using the code block feature.


Root Cause

  • The Markdown renderer was incorrectly wrapping code blocks inside <p>, which is invalid HTML.

  • This caused the hydration error:

    Error: In HTML, <pre> cannot be a descendant of <p>.
    

Fix Implemented

  • ✅ Updated the Markdown rendering logic to ensure that code blocks are rendered as standalone <pre><code>...</code></pre> elements, rather than being wrapped inside <p>.
  • ✅ Prevented unnecessary <p> tags from being applied to code blocks.
  • ✅ Tested rendering different Markdown formats, including inline code (code) and multi-line code blocks (code block).

Related Issues

Checklist

  • Fixes React hydration error ✅
  • Markdown code blocks render correctly ✅
  • No regressions in text formatting ✅
  • Tested across different Markdown scenarios ✅

@LeyoNeuroAI @Asin-Junior-Honore @NeroBlackstone @deyizhi
Would appreciate a review and feedback before merging! 🚀

Let me know if you’d like any modifications! 🎯

Copy link

vercel bot commented Feb 27, 2025

@SaiShanmukkha is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@MaesterPycoder
Copy link

This fix worked perfectly for me! 🚀

The React hydration error caused by <pre> elements being incorrectly nested inside <p> was breaking my Markdown rendering, but after applying this update, everything works as expected.

Code blocks now render correctly without unnecessary <p> tags, and there are no more hydration issues.

Thanks for the quick fix! @SaiShanmukkha

@vaseeem-99
Copy link

I have faced same issue and this fix works.

Thanks @SaiShanmukkha

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

Successfully merging this pull request may close these issues.

Error: In HTML, <pre> cannot be a descendant of <p>. This will cause a hydration error.
3 participants