Skip to content

fix(html): keep an end tag whose omission lets the adoption agency restructure the tree - #21649

Merged
alexander-akait merged 2 commits into
webpack:mainfrom
aryanraj45:fix/html-end-tag-in-formatting-parent
Aug 10, 2026
Merged

alexander-akait merged 2 commits into
webpack:mainfrom
aryanraj45:fix/html-end-tag-in-formatting-parent

Conversation

@aryanraj45

@aryanraj45 aryanraj45 commented Aug 9, 2026 •

Copy link
Copy Markdown
Member

Summary

§13.1.2.4 lets a paragraph or list-item end tag be omitted when nothing follows it in its parent, and the minifier took that permission at face value. Inside a formatting element it does not hold: the element left open is exactly the furthest block the adoption agency looks for when the parent's end tag arrives, so the page re-parses to a different tree — <b><p>x</p></b> printed as <b><p>x</b> re-parses to <b></b><p><b>x</b>. An em wrapping an li breaks the same way. Found by the real-browser DOM equivalence check while adding parser coverage cases.

The end tag is now kept when the parent is an HTML formatting element and the element itself is special. A div or ul parent is unaffected, and no existing snapshot in the suite changed.

What kind of change does this PR introduce?

fix

Did you add tests for your changes?

Yes — test/configCases/html/minimize-end-tag-in-formatting, covering both broken shapes plus two controls that must keep omitting. The fixture is also picked up by the browser equivalence unit test, which failed on it before the fix (11 vs 13 elements) and passes after.

Does this PR introduce a breaking change?

No. Output only grows where it was previously wrong.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

n/a

Use of AI

AI was used. I found the divergence through the browser equivalence check, then used AI to reduce it to a minimal reproduction, locate the rule in the printer, write the regression case and run the suites. I reviewed the change and verified the round-trip and the unaffected cases myself

Summary by CodeRabbit

  • Bug Fixes

    • Improved HTML output minification to preserve required end tags in formatting elements.
    • Prevented serialized HTML from being restructured incorrectly by browser parsing behavior.
  • Tests

    • Added coverage for end-tag minimization across paragraphs, list items, preserved blocks, and inline elements.

…structure the tree

§13.1.2.4 lets a p or li end tag go when nothing follows it in its parent, but
inside a formatting element the element left open is exactly the furthest block
the adoption agency looks for on the parent's end tag: <b><p>x</p></b> printed
as <b><p>x</b> re-parses to a cloned <b> under the <p>. Keep the tag when the
parent is a formatting element and the element is special; div and ul are
unaffected.
@changeset-bot

changeset-bot Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 49a2be2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 1 package
Name Type
webpack Patch

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The HTML minimizer now preserves end tags for special elements nested directly inside formatting elements. This prevents adoption-agency tree restructuring from changing serialized output. A regression fixture covers paragraph, list-item, preserved block, and inline cases. The test configuration builds and minimizes the HTML, then snapshots the emitted page. The changeset documents the correction.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main HTML minification fix for adoption-agency tree restructuring.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f6e232c5-bbb8-4f58-a899-138b1d259379

📥 Commits

Reviewing files that changed from the base of the PR and between 267ef49 and 85d2390.

⛔ Files ignored due to path filters (2)
  • test/configCases/html/minimize-end-tag-in-formatting/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap
  • test/configCases/html/minimize-end-tag-in-formatting/__snapshots__/ConfigTest.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • .changeset/157-html-minify-text-fixes.md
  • lib/html/syntax.js
  • test/configCases/html/minimize-end-tag-in-formatting/index.js
  • test/configCases/html/minimize-end-tag-in-formatting/page.html
  • test/configCases/html/minimize-end-tag-in-formatting/test.config.js
  • test/configCases/html/minimize-end-tag-in-formatting/webpack.config.js
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • webpack/schema-utils (auto-detected)
  • webpack/tapable (auto-detected)

Comment thread lib/html/syntax.js Resolved
@alexander-akait

Copy link
Copy Markdown
Member

Please fix reviews

@github-actions github-actions Bot added the area: html Experimental HTML support (lib/html) label Aug 9, 2026
@aryanraj45

Copy link
Copy Markdown
Member Author

@alexander-akait done shortened the comment to two lines please take a view thanks :))

@codecov

codecov Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.39%. Comparing base (d0a9320) to head (49a2be2).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21649      +/-   ##
==========================================
+ Coverage   94.23%   94.39%   +0.16%     
==========================================
  Files         628      628              
  Lines       79952    80279     +327     
  Branches    23676    23737      +61     
==========================================
+ Hits        75344    75783     +439     
+ Misses       4608     4496     -112     
Flag Coverage Δ
css-parsing 25.88% <ø> (-0.06%) ⬇️
html5lib 30.28% <100.00%> (+2.91%) ⬆️
integration 88.74% <80.00%> (-0.10%) ⬇️
test262 49.08% <ø> (-0.08%) ⬇️
unit 52.22% <80.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed

codspeed Bot commented Aug 9, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 33.43%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
✅ 218 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Memory benchmark "asset-modules-inline", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 397.6 KB 274.8 KB +44.67%
⚡ Memory benchmark "future-defaults", scenario '{"name":"mode-production","mode":"production"}' 10.5 MB 8.5 MB +23.07%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing aryanraj45:fix/html-end-tag-in-formatting-parent (49a2be2) with main (6412396)

Open in CodSpeed

@alexander-akait
alexander-akait merged commit 57f2f2e into webpack:main Aug 10, 2026
103 of 105 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

This PR is packaged and the instant preview is available (57f2f2e).

Install it locally:

  • npm
npm i -D webpack@https://pkg.pr.new/webpack@57f2f2e
  • yarn
yarn add -D webpack@https://pkg.pr.new/webpack@57f2f2e
  • pnpm
pnpm add -D webpack@https://pkg.pr.new/webpack@57f2f2e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: html Experimental HTML support (lib/html)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants