[PR #32419] fix: prevent hydration warning from div nesting inside p for inline markdown images #33733

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

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

State: open
Merged: No


Summary

Fixes #32362

When a markdown paragraph contains an inline image that is not the first child (e.g. Text before ![img](url) text after), the paragraph renderer fell through to a <p> wrapper while the image component rendered block-level <div> elements inside it. This produced invalid HTML (<div> inside <p>) and triggered React/Next.js hydration warnings.

Changes

  • paragraph.tsx: Added hasImageChild() helper to detect any image element among paragraph children. When an image is found (but isn't the first child), renders a <div class="markdown-paragraph"> instead of <p> to avoid invalid nesting.
  • plugin-paragraph.tsx: Same logic applied to the plugin paragraph variant.

How it works

The existing code already handled the case where an image is the first child by rendering a <div> wrapper. This fix extends that pattern to cover images appearing anywhere in the paragraph, ensuring valid HTML output in all cases.

**Original Pull Request:** https://github.com/langgenius/dify/pull/32419 **State:** open **Merged:** No --- ## Summary Fixes #32362 When a markdown paragraph contains an inline image that is **not** the first child (e.g. `Text before ![img](url) text after`), the paragraph renderer fell through to a `<p>` wrapper while the image component rendered block-level `<div>` elements inside it. This produced invalid HTML (`<div>` inside `<p>`) and triggered React/Next.js hydration warnings. ## Changes - **`paragraph.tsx`**: Added `hasImageChild()` helper to detect any image element among paragraph children. When an image is found (but isn't the first child), renders a `<div class="markdown-paragraph">` instead of `<p>` to avoid invalid nesting. - **`plugin-paragraph.tsx`**: Same logic applied to the plugin paragraph variant. ## How it works The existing code already handled the case where an image is the **first** child by rendering a `<div>` wrapper. This fix extends that pattern to cover images appearing **anywhere** in the paragraph, ensuring valid HTML output in all cases.
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#33733