-
Notifications
You must be signed in to change notification settings - Fork 120
fix: Resolve hydration error on news blog pages #498
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: Resolve hydration error on news blog pages #498
Conversation
- Replace figure/div elements with span elements in img component to prevent invalid HTML nesting - Enhance paragraph component to detect and handle block elements more aggressively - Add client-side rendering check to prevent SSR/CSR mismatches - Convert paragraphs containing images to div elements to avoid <div> in <p> nesting - Remove deprecated allowDangerousHtml prop from ReactMarkdown Fixes React hydration error: 'In HTML, <div> cannot be a descendant of <p>' that was occurring when loading news blog posts with images.
❌ Checks Failed
Please fix the following issues before merging: 📝 Code Linting FailedIssue: Code formatting or style violations detected. Specific problems: • Code formatting issues detected How to fix:
Need help with linting? Check out the Linting Guide for Windows Users for detailed instructions. 🛠️ Next Steps
|
- Format MarkdownRenderer.tsx to meet style guidelines - Ensure consistent code style across the project - Fix linting issues for CI/CD pipeline
🎉 All Checks Passed!
✅ Completed Workflows
🚀 This PR is ready for review and can be safely merged to Great work! Your code meets all quality standards. 👏 |
|
hi Maintainers !!@sa-fw-an |
i understood the issue. But even with your PR, I am not able to replicate the solution. as you can see, I'm still getting those issues on my local with your PR open. Maybe demonstrate further? And also, React DOM warnings like THIS one do not stop the app from building or deploying btw. Neither does it lead to slower builds. It's not an actual Hydration error, since www-v2's blogs are pure client sided. The bundler we're using (vite) doesn’t treat this as an error - only React logs it in the browser console. And the deployment works fine. The app will still load in production. Since we're using tags like iframes and embedding the images and videos, the React logging it on browser console is bound to occur only since these tags aren't inherently meant to be {children} of p or div tags. for example, a blogpost with no Image/Video embeddings doesn't throw up any of those issues: (open this on your local) http://localhost:5173/news/all/2025-09-15-dmp-25-weekly-update-aman-chadha but the one with image/video embeddings would: For now, you can work on a method that ignores/suppresses the hydration error for now so that it's not on the browser console in the development environment |
- Add console warning suppression in main.tsx for development mode - Filter out HTML nesting validation warnings (div in p, img in p, etc.) - Maintain all other error/warning visibility - Keep production builds unaffected - Provides cleaner development console for markdown content
❌ Checks Failed
Please fix the following issues before merging: 📝 Code Linting FailedIssue: Code formatting or style violations detected. Specific problems: • TypeScript linting failed How to fix:
Need help with linting? Check out the Linting Guide for Windows Users for detailed instructions. 🛠️ Next Steps
|
- Run prettier formatter to fix linting violations - Ensure consistent code style across all files
❌ Checks Failed
Please fix the following issues before merging: 📝 Code Linting FailedIssue: Code formatting or style violations detected. Specific problems: • TypeScript linting failed How to fix:
Need help with linting? Check out the Linting Guide for Windows Users for detailed instructions. 🛠️ Next Steps
|
- Replace 'any' types with 'unknown' in console method overrides - Ensure strict TypeScript compliance
🎉 All Checks Passed!
✅ Completed Workflows
🚀 This PR is ready for review and can be safely merged to Great work! Your code meets all quality standards. 👏 |
|
@FirePheonix Thanks for the clarification! You're absolutely right - these are React DOM validation warnings about HTML nesting (not actual hydration errors), and they don't affect the build or deployment since this is a client-side only app. I've implemented a solution that suppresses these specific console warnings in development mode by intercepting console.error and console.warn in main.tsx. The suppression: Only runs in development (import.meta.env.DEV) The solution is minimal and targeted - it only suppresses the noise without hiding actual issues. |
|
@FirePheonix @sa-fw-an kindly review the new changes |

Pull Request: Suppress React DOM Nesting Warnings
🔗 Related Issue
Fixes #497 - Hydration Error on News Blog Pages
📝 Description
This PR resolves React DOM nesting warnings that appear in the browser console when loading news blog pages with rich markdown content. These warnings occur due to invalid HTML nesting where block elements like
<div>,<figure>, and<iframe>are rendered inside<p>elements through markdown processing.Warnings Fixed:
Key Changes:
main.tsxfor development mode only🔄 Type of Change
📷 Visual Changes
Before: Console shows hydration error when loading news pages
After: Clean console output with no hydration errors
✅ Test Cases
🔧 Technical Implementation
Root Cause:
ReactMarkdown processes rich markdown content containing images, videos, and other block elements, which can result in invalid HTML nesting when these elements are placed inside paragraph tags. React's DOM validation detects this and logs warnings.
Solution Approach:
Instead of modifying the complex markdown rendering logic, this PR implements a targeted console warning suppression that:
import.meta.env.DEV)Code Changes:
♿ Accessibility
📋 PR Checklist
💭 Additional Notes
Why This Approach?
Alternative Approaches Considered:
Impact:
📚 Reviewer Notes
This PR addresses developer experience by cleaning up console noise while maintaining all existing functionality. The solution is conservative and targeted, affecting only development console output without touching the core markdown rendering logic.
Testing: Load any news article with images/videos (e.g.,
/news/all/2025-09-12-gsoc-25-bishoy-wadea-final-report) and verify the console is clean while all features work normally.