Skip to content

Fix : Custom HTML overflow#77740

Open
Vrishabhsk wants to merge 2 commits into
WordPress:trunkfrom
Vrishabhsk:fix/custom-html-overflow
Open

Fix : Custom HTML overflow#77740
Vrishabhsk wants to merge 2 commits into
WordPress:trunkfrom
Vrishabhsk:fix/custom-html-overflow

Conversation

@Vrishabhsk

Copy link
Copy Markdown
Contributor

What?

  1. Editor preview: Long unbreakable words inside p and blockquote elements in the SandBox iframe overflow horizontally instead of wrapping.
  2. Frontend: Same long words overflow on the published page because the block had no frontend CSS to handle word breaking.

Why?

The Custom HTML block lets users paste arbitrary HTML including long unbreakable words like place names (Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu). When these are wrapped in p or blockquote tags, two things go wrong:

  • Editor: The SandBox iframe constrains the content to the available width, but browser defaults let text flow beyond the container, forcing horizontal scrollbars on pre and clipping on blockquote.
  • Frontend: The save() function rendered raw HTML with no wrapper element and no block-level CSS, so the browser had no instruction to break long words.

This makes valid HTML look broken to both the author and site visitors.

How?

Editor fix

In packages/block-library/src/html/preview.js, the DEFAULT_STYLES string that gets injected into the SandBox iframe was expanded:

p,
blockquote {
	overflow-wrap: break-word;
}

This sits alongside the existing html,body,:root reset and tells the iframe to break long words inside paragraphs and blockquotes instead of overflowing.

Frontend fix

Three small changes ensure the same behavior on the published page:

  1. save.js - Wrapped <RawHTML> in a <div className="wp-block-html"> so the block has a targeting class. Without this, no frontend CSS could reach the raw HTML output.
  2. style.scss - New file with the same overflow-wrap: break-word rule scoped to .wp-block-html p and .wp-block-html blockquote.
  3. block.json - Added "style": "wp-block-html" to register the new stylesheet.

This pattern matches how the Quote, Pullquote, and Code blocks already prevent overflow.

Testing Instructions

  1. Open the post editor.
  2. Insert a Custom HTML block.
  3. Paste the following:
<p>TaumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahuTaumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu</p>

<blockquote>TaumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahuTaumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu</blockquote>
  1. Switch to the block preview (Visual Editor).
  2. Confirm both paragraphs and blockquotes wrap the long word across multiple lines instead of scrolling horizontally.
  3. Publish or preview the post.
  4. On the frontend, confirm the same long word wraps correctly inside both p and blockquote without overflowing the content area.

Use of AI Tools

  • This PR description was authored with the help of kimi-k2.6:cloud model of ollama.
  • The recommended fix was produced by kimi-k2.6:cloud model of ollama which was tested and implemented

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Apr 28, 2026
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Vrishabhsk <vrishabhsk@git.wordpress.org>
Co-authored-by: Mayank-Tripathi32 <mayanktripathi32@git.wordpress.org>
Co-authored-by: 3kori <r1k0@git.wordpress.org>
Co-authored-by: meravi <ravikhadka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Vrishabhsk Vrishabhsk changed the title Fix/custom html overflow Fix : Custom HTML overflow Apr 28, 2026
@im3dabasia im3dabasia added [Type] Bug An existing feature does not function as intended [Block] HTML Affects the the HTML Block labels Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] HTML Affects the the HTML Block [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom HTML block: <pre> and <blockquote> display with forced overflow scroll and incorrect formatting

2 participants