[PR #32425] fix: prevent hydration error from div nested inside p in markdown renderer #33732

Open
opened 2026-02-21 20:53:47 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/32425

State: open
Merged: No


Summary

Fixes a Next.js hydration warning caused by invalid DOM nesting when markdown paragraphs contain inline images that aren't the first child.

Before: Text ![img](url) text renders as <p>Text <div class="markdown-img-wrapper">...</div> text</p> — invalid HTML (<div> inside <p>).

After: Detects img children at any position and renders <div> instead of <p> when images are present.

Changes

  • web/app/components/base/markdown-blocks/paragraph.tsx: Added fallback check for img children at non-first positions. When found, renders <div> instead of <p> to prevent invalid nesting.

The existing first-child image handling (which extracts the image into an ImageGallery) is preserved unchanged.

Closes #32362

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/langgenius/dify/pull/32425 **State:** open **Merged:** No --- ## Summary Fixes a Next.js hydration warning caused by invalid DOM nesting when markdown paragraphs contain inline images that aren't the first child. **Before:** `Text ![img](url) text` renders as `<p>Text <div class="markdown-img-wrapper">...</div> text</p>` — invalid HTML (`<div>` inside `<p>`). **After:** Detects `img` children at any position and renders `<div>` instead of `<p>` when images are present. ## Changes - **`web/app/components/base/markdown-blocks/paragraph.tsx`**: Added fallback check for `img` children at non-first positions. When found, renders `<div>` instead of `<p>` to prevent invalid nesting. The existing first-child image handling (which extracts the image into an `ImageGallery`) is preserved unchanged. Closes #32362 🤖 Generated with [Claude Code](https://claude.ai/claude-code)
yindo added the pull-request label 2026-02-21 20:53:47 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33732