GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(html): read past the whitespace collapseWhitespace removes when omitting an end tag by aryanraj45 · Pull Request #21694 · webpack/webpack

Conversation

@aryanraj45

@aryanraj45 aryanraj45 commented Aug 12, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Summary

Follow-up to #21685. collapseWhitespace in "smart" and "all" empties a whitespace-only text node, but _canOmitEndTag reads the AST, so the node was still there when it decided — and an optional end tag that only existed because of that whitespace stayed. <li>a</li> <li>b</li> collapsed to <li>a</li><li>b</li> rather than <li>a<li>b.

It now reads past a node the mode is certain to drop, which is what its own doc comment already described. Nothing changes in "conservative", where the whitespace survives as one space and really does keep the tag.

Worth 4976 raw / 228 gzip bytes on top of "smart", measured over html5-boilerplate, swagger-ui and the rendered README and CHANGELOG — most of what the mode saves on a document turns out to be the end tags rather than the spaces.

What kind of change does this PR introduce?

fix

Did you add tests for your changes?

Yes — a case in the existing collapseWhitespace unit suite, and list and table markup added to the smart-mode fixture under configCases/html so the snapshot and the real-Chrome DOM equivalence check both cover it. Every added line is covered. The output was also compared against parse5 over 36 fixtures: what a browser paints is unchanged.

Does this PR introduce a breaking change?

No. Only the two modes that already remove the whitespace are affected.

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

n/a — no new option, the existing descriptions still hold.

Use of AI

AI was used. I found the gap while measuring the modes against other minifiers and decided the scope; Claude Code did the implementation and tests. I reviewed it before pushing

Summary by CodeRabbit

  • Bug Fixes

    • Improved HTML whitespace collapsing so removed whitespace remains correctly associated with nearby end tags.
    • Smart and all whitespace-collapsing modes now handle optional closing tags more accurately.
    • Preserved meaningful whitespace and closing tags within preformatted content such as <pre> blocks.
    • Improved cleanup of redundant list-item closing tags when smart collapsing removes surrounding whitespace.
  • Tests

    • Added coverage for lists, tables, inline elements, and preformatted content.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@aryanraj45
fix(html): let an end tag go with the whitespace collapseWhitespace r…
c6822c5
…emoves

`_canOmitEndTag` reads the AST, so a whitespace node kept the tag even in the
modes that empty that node — `<li>a</li> <li>` stayed as it was. It now reads
past a node the mode is certain to drop, which is what its own doc already
claimed. 4976 raw / 228 gzip over the four benchmark documents.
@changeset-bot

changeset-bot Bot commented Aug 12, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b71cd23

The changes in this PR will be included in the next version bump.

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

Not sure what this means? Click here to learn what changesets are.

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

coderabbitai Bot commented Aug 12, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "tools"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
📝 Walkthrough

Walkthrough

Whitespace collapsing now accounts for whitespace-only nodes when omitting optional HTML end tags. Preformatted content remains protected. Tests and fixtures cover list-item and <pre> behavior.

Changes

HTML whitespace and end tags

Layer / File(s) Summary
Whitespace-aware end-tag evaluation
lib/html/syntax.js
Whitespace-only nodes and preformatted ancestors use shared checks. Optional end-tag evaluation skips whitespace removed by "all" or eligible "smart" collapsing.
List formatting regression coverage
test/HtmlSyntax.unittest.js, test/configCases/html/minimize-comments-and-whitespace/page.html, .changeset/160-html-end-tag-past-whitespace.md
Tests and fixtures cover list-item whitespace removal and preservation of paragraph end tags inside <pre>. The changeset documents the behavior.

Possibly related PRs

  • webpack/webpack#21649: Both changes modify optional end-tag omission logic in lib/html/syntax.js.
  • webpack/webpack#21663: Both changes modify whitespace collapsing in lib/html/syntax.js.
  • webpack/webpack#21677: Both changes refine tag-omission handling in lib/html/syntax.js.

Suggested reviewers: alexander-akait

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title uses the required Conventional Commit form and accurately describes the HTML end-tag omission fix, but the branch prefix is not provided. Provide the branch name or confirm that its prefix is fix.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Caution

CodeRabbit couldn't update its existing comment. The review summary may be out of date.

Error details
putComment timed out
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

coderabbitai[bot]
coderabbitai Bot reviewed Aug 12, 2026
View reviewed changes

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
lib/html/syntax.js (1)

8494-8501: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten the new helper comments.

Keep the required JSDoc type annotations, but reduce the explanatory prose to one or two short lines.

As per coding guidelines and path instructions, comments in lib/ must be at most two short lines and add non-obvious information.

Also applies to: 8503-8516, 8518-8527

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/html/syntax.js` around lines 8494 - 8501, Shorten the JSDoc comments for
_isWhitespaceNode and the additional helpers at the referenced locations to one
or two concise lines, while preserving the required `@param` and `@returns` type
annotations. Keep only non-obvious information and remove verbose explanatory
prose.

Sources: Coding guidelines, Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/html/syntax.js`:
- Around line 8552-8569: Update the whitespace-skipping logic in the surrounding
sibling traversal for both “all” and “smart” modes to require the printer’s
existing actual-removability predicate, including its
LEADING_NEWLINE_ELEMENTS/preformatted guard, before advancing past a whitespace
node. Preserve the existing mode-specific conditions, and add a regression test
covering whitespace between elements inside a preformatted ancestor such as
`<pre><p>a</p>\n<p>b</p></pre>`.

---

Nitpick comments:
In `@lib/html/syntax.js`:
- Around line 8494-8501: Shorten the JSDoc comments for _isWhitespaceNode and
the additional helpers at the referenced locations to one or two concise lines,
while preserving the required `@param` and `@returns` type annotations. Keep only
non-obvious information and remove verbose explanatory prose.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 43e3cd9b-d697-4fcc-86bc-14e19b6bdd27

📥 Commits

Reviewing files that changed from the base of the PR and between 1347dc5 and c6822c5.

⛔ Files ignored due to path filters (2)
  • test/configCases/html/minimize-comments-and-whitespace/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**
  • test/configCases/html/minimize-comments-and-whitespace/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**
📒 Files selected for processing (4)
  • .changeset/160-html-end-tag-past-whitespace.md
  • lib/html/syntax.js
  • test/HtmlSyntax.unittest.js
  • test/configCases/html/minimize-comments-and-whitespace/page.html
🔗 Linked repositories identified

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/html/syntax.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@aryanraj45
fix(html): keep an end tag whose whitespace an ancestor renders verbatim
b71cd23
The skip loop treated every whitespace-only sibling as removable, but the
printer leaves text under a pre / textarea / listing ancestor exactly as
written — so the tag went and the whitespace merged into the text before it.
Both sides now ask the same guard, lifted out of the printer.
coderabbitai[bot]
coderabbitai Bot reviewed Aug 12, 2026
View reviewed changes

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/configCases/html/minimize-comments-and-whitespace/page.html (1)

13-23: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add focused assertions for the new whitespace cases.

The snapshot in test/configCases/html/minimize-comments-and-whitespace/test.config.js (Lines [11-32]) covers the full page, but its explicit assertions do not cover the added list, table, inline, or multiline <pre> output. Add expect(page) checks for these cases. Ensure at least one assertion fails with the pre-fix output. Run yarn test:basic --testPathPatterns="ConfigTestCases" after the change.

As per path instructions, test/** requires explicit expect() checks for behavior, and test/configCases/** requires coverage for each added or changed line.

Also applies to: 25-26

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/configCases/html/minimize-comments-and-whitespace/page.html` around
lines 13 - 23, Add focused expect(page) assertions in the config-case test
covering the added list, table, inline, and multiline pre whitespace output,
using selectors or text checks that distinguish the expected minimized markup
and ensure at least one assertion fails before the fix. Run the ConfigTestCases
basic test command to verify the assertions.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@test/configCases/html/minimize-comments-and-whitespace/page.html`:
- Around line 13-23: Add focused expect(page) assertions in the config-case test
covering the added list, table, inline, and multiline pre whitespace output,
using selectors or text checks that distinguish the expected minimized markup
and ensure at least one assertion fails before the fix. Run the ConfigTestCases
basic test command to verify the assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5d4abaf7-aea9-4f8e-bdf7-748439b2ddb0

📥 Commits

Reviewing files that changed from the base of the PR and between c6822c5 and b71cd23.

⛔ Files ignored due to path filters (2)
  • test/configCases/html/minimize-comments-and-whitespace/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**
  • test/configCases/html/minimize-comments-and-whitespace/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**
📒 Files selected for processing (3)
  • lib/html/syntax.js
  • test/HtmlSyntax.unittest.js
  • test/configCases/html/minimize-comments-and-whitespace/page.html
🔗 Linked repositories identified

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

  • webpack/schema-utils (auto-detected)
  • webpack/tapable (auto-detected)
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/HtmlSyntax.unittest.js
  • lib/html/syntax.js

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@aryanraj45 aryanraj45 mentioned this pull request Aug 13, 2026
feat(html): add optimization.minimize.html.tagOmission #21678
Closed
@aryanraj45

aryanraj45 commented Aug 13, 2026

Copy link
Copy Markdown
Member Author

closing in favour of #21700

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aryanraj45 aryanraj45 closed this Aug 13, 2026
This was referenced Aug 14, 2026
fix(html): drop a shell tag kept for whitespace that prints nothing, and respell escaped quotes #21717
Merged
added <li> to P_FOLLOWED_BY #21734
Closed
fix(html): keep the end tags the parser cannot put back, and mirror <selectedcontent> as an engine does #21743
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

area: html Experimental HTML support (lib/html)

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@aryanraj45
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.