GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(html): offer dropping an attribute that restates the default by alexander-akait · Pull Request #21685 · webpack/webpack Conversation
|
🦋 Changeset detectedLatest commit: 0ef9dbe The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Note
|
| Layer / File(s) | Summary |
|---|---|
Option contracts and pipeline wiring schemas/WebpackOptions.json, lib/html/htmlMinify.js, lib/util/SourceProcessor.js, .changeset/... |
The new minimizer options are documented, schema-validated, typed, and forwarded to the print context. |
Attribute metadata and normalization tooling/generate-html-data.js, lib/html/syntax.js |
Generated lookup tables support empty and redundant attribute detection. The printer removes configured attributes and empty elements, deduplicates class tokens, and optionally sorts attributes and class names. |
Structural tag omission and adjacent style merging lib/html/syntax.js, tooling/generate-html-data.js |
The printer omits eligible structural tags and merges compatible adjacent CSS <style> elements. Rejected CSS, ordering-sensitive at-rules, comments, and blocking elements preserve required boundaries. |
Minimization behavior validation test/HtmlSyntax.unittest.js, test/configCases/html/minimize-* |
Unit and emitted-HTML tests cover option behavior, preserved exceptions, CSS merge safeguards, structural tag omission, sorting, and redundant-attribute modes. |
Possibly related PRs
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title uses the required Conventional Commit form and accurately describes the redundant HTML attribute removal feature. |
| 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. |
feat/html-remove-redundant-attributesComment @coderabbitai help to get the list of available commands.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
This PR is packaged and the instant preview is available (9db1341). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@9db1341
yarn add -D webpack@https://pkg.pr.new/webpack@9db1341
pnpm add -D webpack@https://pkg.pr.new/webpack@9db1341 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@ ## main #21685 +/- ## ========================================== - Coverage 94.51% 94.49% -0.03% ========================================== Files 631 631 Lines 82402 82727 +325 Branches 24422 24580 +158 ========================================== + Hits 77885 78172 +287 - Misses 4517 4555 +38
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
tooling/generate-html-data.js (1)
1185-1214: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftDo not hand-maintain the redundant-attribute metadata.
Derive these mappings from a published dataset. If a source cannot provide them, add a
SUPPLEMENTentry that states why.As per path instructions: “Generators must derive tables from published datasets … rather than hand-typing name lists; a SUPPLEMENT entry needs a stated reason it cannot be derived.”
🤖 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 `@tooling/generate-html-data.js` around lines 1185 - 1214, Replace the hand-maintained REDUNDANT_TYPE_ATTRIBUTES and REDUNDANT_DEFAULT_ATTRIBUTES mappings with data derived from the applicable published dataset. For any attributes the dataset cannot provide, add a SUPPLEMENT entry documenting the specific reason they require manual coverage, while preserving the existing metadata structure and values.Source: Path instructions
lib/html/htmlMinify.js (1)
63-65: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten this source comment.
Keep the comment to two short lines or fewer.
As per coding guidelines: “Keep comments as short as possible, generally one line and no more than two short lines.” As per path instructions: “Comments must be at most two short lines and add non-obvious information.”
🤖 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/htmlMinify.js` around lines 63 - 65, Shorten the comment near process and minimize to no more than two brief lines, retaining only the non-obvious points that processing parses once and that the returned map is unused because HTML serialization produces no mappings.Sources: Coding guidelines, Path instructions
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 9063-9067: Update the attribute-processing flow around
_isRedundantAttribute to extract rawValue before branching on quoted values,
then check and remove redundant values for both quoted and unquoted attributes
when the selected mode permits it. Preserve the existing consumedEnd handling
and continue behavior before entering value rewriting.
In `@test/configCases/html/minimize-redundant-attributes/page.html`:
- Line 15: Wrap the standalone td element in
test/configCases/html/minimize-redundant-attributes/page.html with table, tbody,
and tr elements so it is parsed as a table cell and the snapshot can verify
retention of colspan="1".
In `@test/configCases/html/minimize-redundant-attributes/webpack.config.js`:
- Around line 12-14: Add a separate integration configuration case alongside the
existing minimize-redundant-attributes case, using removeRedundantAttributes set
to "all" instead of "smart". Include assertions verifying that default-valued
HTML attributes are removed, covering the new "all" mode branch while preserving
the existing smart-mode case.
---
Nitpick comments:
In `@lib/html/htmlMinify.js`:
- Around line 63-65: Shorten the comment near process and minimize to no more
than two brief lines, retaining only the non-obvious points that processing
parses once and that the returned map is unused because HTML serialization
produces no mappings.
In `@tooling/generate-html-data.js`:
- Around line 1185-1214: Replace the hand-maintained REDUNDANT_TYPE_ATTRIBUTES
and REDUNDANT_DEFAULT_ATTRIBUTES mappings with data derived from the applicable
published dataset. For any attributes the dataset cannot provide, add a
SUPPLEMENT entry documenting the specific reason they require manual coverage,
while preserving the existing metadata structure and values.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 78219f1b-b293-451e-80d4-e4c5450c223a
declarations/WebpackOptions.d.ts is excluded by !declarations/**lib/html/data.js is excluded by !lib/html/data.jsschemas/WebpackOptions.check.js is excluded by !schemas/**/*.check.jstest/__snapshots__/Cli.basictest.js.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-redundant-attributes/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-redundant-attributes/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**types.d.ts is excluded by !types.d.ts.changeset/048-html-remove-redundant-attributes.mdlib/html/htmlMinify.jslib/html/syntax.jslib/util/SourceProcessor.jsschemas/WebpackOptions.jsontest/configCases/html/minimize-redundant-attributes/index.jstest/configCases/html/minimize-redundant-attributes/page.htmltest/configCases/html/minimize-redundant-attributes/test.config.jstest/configCases/html/minimize-redundant-attributes/webpack.config.jstooling/generate-html-data.jsCodeRabbit considers these linked repositories for cross-repo context during reviews:
webpack/schema-utils (auto-detected)webpack/tapable (auto-detected)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| optimization: { | ||
| minimize: { html: { removeRedundantAttributes: "smart" } }, | ||
| minimizer: ["..."] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Add an integration case for "all" mode.
This case exercises only "smart". Add a separate configuration case that uses "all" and asserts removal of default-valued attributes.
As per coding guidelines: “Cover every changed line and branch with tests, preferably through integration cases.”
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-redundant-attributes/webpack.config.js` around
lines 12 - 14, Add a separate integration configuration case alongside the
existing minimize-redundant-attributes case, using removeRedundantAttributes set
to "all" instead of "smart". Include assertions verifying that default-valued
HTML attributes are removed, covering the new "all" mode branch while preserving
the existing smart-mode case.
Source: Coding guidelines
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Generated code sizeComparing
167 asset(s) changed size, biggest 20 by raw change
54 runtime(s) changed which runtime modules they carry, biggest 20 by number moved
Built |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Merging this PR will improve performance by 42.52%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Memory | benchmark "future-defaults", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
336.3 KB | 236 KB | +42.52% |
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 feat/html-remove-redundant-attributes (0ef9dbe) with main (7299185)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
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 `@tooling/generate-html-data.js`:
- Around line 1190-1196: The smart-mode attribute list around the selector
mappings must not include style type, link type/media, or script
language/charset entries because these attributes are observable by selectors
and scripts. Move these entries from the smart configuration to the all
configuration, preserving smart mode only for attributes safe to omit and
keeping the existing lib/html/syntax.js mapping behavior consistent.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: ea7da349-8d4f-472e-92d2-ebfc2cd76679
declarations/WebpackOptions.d.ts is excluded by !declarations/**lib/html/data.js is excluded by !lib/html/data.jsschemas/WebpackOptions.check.js is excluded by !schemas/**/*.check.jstest/__snapshots__/Cli.basictest.js.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-redundant-attributes-all/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-redundant-attributes-all/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-redundant-attributes/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-redundant-attributes/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-transforms/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-transforms/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**types.d.ts is excluded by !types.d.ts.changeset/048-html-remove-redundant-attributes.mdlib/html/htmlMinify.jslib/html/syntax.jslib/util/SourceProcessor.jsschemas/WebpackOptions.jsontest/configCases/html/minimize-redundant-attributes-all/index.jstest/configCases/html/minimize-redundant-attributes-all/page.htmltest/configCases/html/minimize-redundant-attributes-all/test.config.jstest/configCases/html/minimize-redundant-attributes-all/webpack.config.jstest/configCases/html/minimize-redundant-attributes/index.jstest/configCases/html/minimize-redundant-attributes/page.htmltest/configCases/html/minimize-redundant-attributes/test.config.jstest/configCases/html/minimize-redundant-attributes/webpack.config.jstooling/generate-html-data.jsCodeRabbit considers these linked repositories for cross-repo context during reviews:
webpack/schema-utils (auto-detected)webpack/tapable (auto-detected)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
lib/html/syntax.js (1)
8611-8625: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten the new explanatory comments.
Keep each comment to one or two short lines. Retain only information that the code or test name does not show.
lib/html/syntax.js#L8611-L8625: reduce the absorbed-style and CSS-minification prose.lib/html/syntax.js#L9019-L9028: reduce the merge-algorithm rationale.test/HtmlSyntax.unittest.js#L3717-L3721: reduce the unit-test scope explanation.test/configCases/html/minimize-empty-attributes/test.config.js#L20-L25: reduce the character-reference andtitle/langexplanations.As per coding guidelines: “Keep comments as short as possible, generally one line and no more than two short lines.”
🤖 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 8611 - 8625, Shorten the explanatory comments at lib/html/syntax.js lines 8611-8625, 9019-9028, test/HtmlSyntax.unittest.js lines 3717-3721, and test/configCases/html/minimize-empty-attributes/test.config.js lines 20-25. Keep each comment to one or two short lines, retaining only details not evident from the surrounding code or test names; do not change behavior.Source: Coding guidelines
tooling/generate-html-data.js (1)
1185-1193: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten the new tooling comments.
This explanatory block spans more than two short lines. Keep only the non-obvious exclusion rule here. Move the detailed
title,lang, and URL semantics to the option documentation.Proposed simplification
- // Global attributes whose empty value is the state the spec gives their - // absence, so `removeEmptyAttributes` may drop them. Deliberately short: - // `title=""` and `lang=""` look like members and are not, because the spec - // gives each of them a meaning absence does not have — an empty `title` says - // the element has no advisory information, overriding an ancestor's, and an - // empty `lang` says the language is unknown rather than inherited. Every - // other minifier drops both. `href` / `src` / `action` are out for the same - // reason: an empty URL resolves to the document's own address, which is not - // what no URL at all does. + // Empty class, dir, id, and style values may be removed when enabled. + // Keep title, lang, href, src, and action because empty differs from absent.As per coding guidelines, comments should be “generally one line and no more than two short lines.”
As per path instructions,tooling/**comments “must be at most two short lines.”🤖 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 `@tooling/generate-html-data.js` around lines 1185 - 1193, Shorten the comment above the global empty-value attribute list to at most two short lines, retaining only the non-obvious exclusion rule for attributes such as title, lang, href, src, and action. Move the detailed attribute semantics into the relevant option documentation.Sources: Coding guidelines, Path instructions
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 10123-10125: Restore the opt-in default by setting
_removeRedundantAttributes in lib/html/syntax.js:10123-10125 to "none". Update
schemas/WebpackOptions.json:3720-3723 to accept and document "none" as the
default, add "none" to PrintOptions["removeRedundantAttributes"] in
lib/util/SourceProcessor.js:43, and update the forwarded process-option type and
default-output handling in lib/util/SourceProcessor.js:694-712 to support
"none".
---
Nitpick comments:
In `@lib/html/syntax.js`:
- Around line 8611-8625: Shorten the explanatory comments at lib/html/syntax.js
lines 8611-8625, 9019-9028, test/HtmlSyntax.unittest.js lines 3717-3721, and
test/configCases/html/minimize-empty-attributes/test.config.js lines 20-25. Keep
each comment to one or two short lines, retaining only details not evident from
the surrounding code or test names; do not change behavior.
In `@tooling/generate-html-data.js`:
- Around line 1185-1193: Shorten the comment above the global empty-value
attribute list to at most two short lines, retaining only the non-obvious
exclusion rule for attributes such as title, lang, href, src, and action. Move
the detailed attribute semantics into the relevant option documentation.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: fbc30abd-f981-4353-b766-6392555e5783
declarations/WebpackOptions.d.ts is excluded by !declarations/**lib/html/data.js is excluded by !lib/html/data.jsschemas/WebpackOptions.check.js is excluded by !schemas/**/*.check.jstest/__snapshots__/Cli.basictest.js.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-empty-attributes/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-empty-attributes/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-merge-styles/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-merge-styles/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**types.d.ts is excluded by !types.d.ts.changeset/048-html-remove-redundant-attributes.mdlib/html/htmlMinify.jslib/html/syntax.jslib/util/SourceProcessor.jsschemas/WebpackOptions.jsontest/HtmlSyntax.unittest.jstest/configCases/html/minimize-empty-attributes/index.jstest/configCases/html/minimize-empty-attributes/page.htmltest/configCases/html/minimize-empty-attributes/test.config.jstest/configCases/html/minimize-empty-attributes/webpack.config.jstest/configCases/html/minimize-merge-styles/index.jstest/configCases/html/minimize-merge-styles/page.htmltest/configCases/html/minimize-merge-styles/test.config.jstest/configCases/html/minimize-merge-styles/webpack.config.jstooling/generate-html-data.jsCodeRabbit considers these linked repositories for cross-repo context during reviews:
webpack/schema-utils (auto-detected)webpack/tapable (auto-detected)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
lib/html/syntax.js (1)
8615-8622: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten the added comments.
These comments exceed two short lines. Several restate nearby code. Keep only non-obvious constraints.
lib/html/syntax.js#L8615-L8622: reduce the state-option comments to short declarations.lib/html/syntax.js#L8778-L8788: reduce the empty-element rationale to a short safety note.lib/html/syntax.js#L8816-L8819: reduce the token-list behavior description.lib/html/syntax.js#L8886-L8888: reduce theclass-only sorting explanation.lib/html/syntax.js#L9192-L9195: reduce the attribute-ordering explanation.🤖 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 8615 - 8622, Shorten the comments in lib/html/syntax.js at lines 8615-8622, 8778-8788, 8816-8819, 8886-8888, and 9192-9195: reduce the state-option notes to brief declarations, retain only a short safety note for empty elements, and condense the token-list, class-only sorting, and attribute-ordering explanations to their non-obvious constraints.Sources: Coding guidelines, Path instructions
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 8824-8834: Update _normalizeTokenList so the default sort=false
path preserves duplicate tokens and returns the collapsed token string
unchanged. Only deduplicate tokens when an explicit removal option is enabled;
do not let the existing sort flag remove duplicates, preserving class attribute
values such as "a a".
In `@schemas/WebpackOptions.json`:
- Around line 3720-3738: Regenerate the public TypeScript declarations for the
new removeEmptyElements, removeRedundantAttributes, sortAttributes, and
sortClassNames schema options by running yarn fix:special, then include the
generated types.d.ts outputs in the change.
---
Nitpick comments:
In `@lib/html/syntax.js`:
- Around line 8615-8622: Shorten the comments in lib/html/syntax.js at lines
8615-8622, 8778-8788, 8816-8819, 8886-8888, and 9192-9195: reduce the
state-option notes to brief declarations, retain only a short safety note for
empty elements, and condense the token-list, class-only sorting, and
attribute-ordering explanations to their non-obvious constraints.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 782a9f2d-8bff-4bfe-8902-e221caf7e638
declarations/WebpackOptions.d.ts is excluded by !declarations/**lib/html/data.js is excluded by !lib/html/data.jsschemas/WebpackOptions.check.js is excluded by !schemas/**/*.check.jstest/__snapshots__/Cli.basictest.js.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-empty-elements/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-empty-elements/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-sort/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-sort/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-transforms/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-transforms/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**.changeset/048-html-remove-redundant-attributes.mdlib/html/htmlMinify.jslib/html/syntax.jslib/util/SourceProcessor.jsschemas/WebpackOptions.jsontest/HtmlSyntax.unittest.jstest/configCases/html/minimize-empty-elements/index.jstest/configCases/html/minimize-empty-elements/page.htmltest/configCases/html/minimize-empty-elements/test.config.jstest/configCases/html/minimize-empty-elements/webpack.config.jstest/configCases/html/minimize-sort/index.jstest/configCases/html/minimize-sort/page.htmltest/configCases/html/minimize-sort/test.config.jstest/configCases/html/minimize-sort/webpack.config.jstooling/generate-html-data.jsCodeRabbit considers these linked repositories for cross-repo context during reviews:
webpack/schema-utils (auto-detected)webpack/tapable (auto-detected)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const _normalizeTokenList = (raw, sort) => { | ||
| const collapsed = _asciiTrim(raw).replace(/[\t\n\f\r ]+/g, " "); | ||
| if (!collapsed.includes(" ")) return collapsed; | ||
| const tokens = collapsed.split(" "); | ||
| let duplicated = false; | ||
| for (let i = 1; i < tokens.length && !duplicated; i++) { | ||
| duplicated = tokens.indexOf(tokens[i]) !== i; | ||
| } | ||
| if (!duplicated && !sort) return collapsed; | ||
| const unique = duplicated ? [...new Set(tokens)] : tokens; | ||
| return (sort ? unique.sort() : unique).join(" "); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Preserve duplicate class tokens unless removal is explicitly enabled.
When sort is false, <div class="a a"> becomes <div class="a">. This changes selectors such as [class="a a"] and getAttribute("class") during default minimization. Keep duplicate tokens, or add a separate opt-in option for removing them.
const tokens = collapsed.split(" ");
- let duplicated = false;
- for (let i = 1; i < tokens.length && !duplicated; i++) {
- duplicated = tokens.indexOf(tokens[i]) !== i;
- }
- if (!duplicated && !sort) return collapsed;
- const unique = duplicated ? [...new Set(tokens)] : tokens;
- return (sort ? unique.sort() : unique).join(" ");
+ if (!sort) return collapsed;
+ return tokens.sort().join(" ");
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const _normalizeTokenList = (raw, sort) => { | |
| const collapsed = _asciiTrim(raw).replace(/[\t\n\f\r ]+/g, " "); | |
| if (!collapsed.includes(" ")) return collapsed; | |
| const tokens = collapsed.split(" "); | |
| let duplicated = false; | |
| for (let i = 1; i < tokens.length && !duplicated; i++) { | |
| duplicated = tokens.indexOf(tokens[i]) !== i; | |
| } | |
| if (!duplicated && !sort) return collapsed; | |
| const unique = duplicated ? [...new Set(tokens)] : tokens; | |
| return (sort ? unique.sort() : unique).join(" "); | |
| const _normalizeTokenList = (raw, sort) => { | |
| const collapsed = _asciiTrim(raw).replace(/[\t\n\f\r ]+/g, " "); | |
| if (!collapsed.includes(" ")) return collapsed; | |
| const tokens = collapsed.split(" "); | |
| if (!sort) return collapsed; | |
| return tokens.sort().join(" "); |
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 8824 - 8834, Update _normalizeTokenList so
the default sort=false path preserves duplicate tokens and returns the collapsed
token string unchanged. Only deduplicate tokens when an explicit removal option
is enabled; do not let the existing sort flag remove duplicates, preserving
class attribute values such as "a a".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
tooling/generate-html-data.js (1)
286-289: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten the new explanatory comments.
Reduce each new comment to one or two short lines. Keep the required spec reference and the non-obvious parser constraint.
tooling/generate-html-data.js#L286-L289: shorten the wrapper end-tag comment.tooling/generate-html-data.js#L1319-L1325: shorten the body start-tag blocker comment.tooling/generate-html-data.js#L1513-L1528: shorten the generated comments emitted into thelib/source file.As per coding guidelines, “Keep comments as short as possible, generally one line and no more than two short lines.”
🤖 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 `@tooling/generate-html-data.js` around lines 286 - 289, Shorten the explanatory comments in tooling/generate-html-data.js at lines 286-289, 1319-1325, and 1513-1528 to one or two brief lines each. Preserve the required specification reference and the non-obvious parser constraints, including the wrapper end-tag, body start-tag, and generated lib/ comments; no code behavior changes are needed.Source: Coding guidelines
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tooling/generate-html-data.js`:
- Around line 286-289: Shorten the explanatory comments in
tooling/generate-html-data.js at lines 286-289, 1319-1325, and 1513-1528 to one
or two brief lines each. Preserve the required specification reference and the
non-obvious parser constraints, including the wrapper end-tag, body start-tag,
and generated lib/ comments; no code behavior changes are needed.
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 4b05144c-2c63-4d4b-be05-ba3a5cd98160
declarations/WebpackOptions.d.ts is excluded by !declarations/**lib/html/data.js is excluded by !lib/html/data.jstest/__snapshots__/Cli.basictest.js.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-attributes/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-attributes/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-collapse-whitespace/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-collapse-whitespace/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-css-options/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-css-options/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-empty-attributes/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-empty-attributes/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-empty-elements/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-empty-elements/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-end-tag-in-formatting/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-end-tag-in-formatting/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-environment/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-environment/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-merge-styles/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-merge-styles/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-redundant-attributes-all/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-redundant-attributes-all/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-redundant-attributes/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-redundant-attributes/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-sort/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-sort/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-transforms/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/minimize-transforms/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/parser-foreign-content/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/parser-foreign-content/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/parser-foster-parenting/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/parser-foster-parenting/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/parser-template-insertion-mode/__snapshots__/ConfigCacheTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**test/configCases/html/parser-template-insertion-mode/__snapshots__/ConfigTest.snap is excluded by !**/*.snap, !test/**/__snapshots__/**types.d.ts is excluded by !types.d.tslib/html/syntax.jsschemas/WebpackOptions.jsontest/HtmlSyntax.unittest.jstest/configCases/html/minimize-redundant-attributes/page.htmltest/configCases/html/minimize-redundant-attributes/test.config.jstooling/generate-html-data.jsCodeRabbit considers these linked repositories for cross-repo context during reviews:
webpack/schema-utils (auto-detected)webpack/tapable (auto-detected)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Other minifiers drop `<script type=text/javascript>` and `<input type=text>`; webpack kept both, because an attribute selector matches the content attribute rather than the reflected default, so `input[type=text]` stops matching. Add `optimization.minimize.html.removeRedundantAttributes`, `"none"` by default. `"smart"` drops only the type/language markers no stylesheet selects on, which is what @swc/html does by default; `"all"` also drops the spec defaults, which is the unsafe part. The two tables are generated, and the JavaScript spellings reuse `JAVASCRIPT_SCRIPT_TYPES` rather than a second list. The flags are read where the walk starts, not in `printer`: a tag streams out before the first `printer` call, so setting them there left a top-level tag unaffected.
Measured what @swc/html drops at its default: also `<link media=all>` on any `rel`, and `<script charset=utf-8>`, which is obsolete and ignored when it matches the document encoding. `<style media=all>` is kept, as it is there. Matched ASCII-case-insensitively throughout. @swc/html lowercases `type` but not `media` or `charset`, so it keeps `media=ALL` and `charset=UTF-8` while dropping the lowercase spellings — an inconsistency not worth copying.
`removeRedundantAttributes` now defaults to "smart" and no longer takes "none": that tier only drops the type/language/charset markers nothing a selector or script reads can observe, which is what @swc/html does by default. "all" stays opt-in — it drops spec defaults like `input[type=text]`, which an attribute selector does match.
Now that it runs by default it sees every printed attribute, and almost none is on an element either table names. Group the tables by element in the generator so one lookup gates, instead of trimming, lowercasing and building an `element attribute` key first. On a 2000-attribute body that is 2000 fewer key strings and 4000 fewer scans; zero on the miss path.
Two adjacent `<style>` with the same attributes print as one. Adjacency is what makes it safe: only whitespace may lie between, nothing is hoisted, so the cascade is the one the source wrote. Each sheet is minified before it is joined rather than after — text the minifier could not read may be unterminated, and appending to that makes the next sheet part of its last rule. A sheet after the first carrying `@import` is left alone too, since an import only applies at the top of a sheet. @swc/html, the only other tool that folds by default, gets both of those wrong. `removeEmptyAttributes` drops `class` / `id` / `style` / `dir` when the value is empty, which is the state the spec also gives their absence. Off by default: a presence selector still matches an empty value. `title` and `lang` are deliberately not in the table even though every other minifier drops them — the spec gives an empty `title` the meaning "no advisory information", overriding an ancestor's, and an empty `lang` the meaning "language unknown" rather than the inherited one.
A token list is a set — the ordered set parser drops a repeat — so a repeated `class` token was never a second token, and the value is already rewritten in place next to this. Sorting is not free that way: nothing in HTML or CSS reads attribute or class order, but a script reading `element.attributes` or `className` back does, so `sortAttributes` and `sortClassNames` are opt-in. Both are reorderings only — the byte count is unchanged and a test pins that, alongside one comparing the canonical DOM of the sorted output against the unsorted.
Every guard but the name table is a rule rather than a list: a void element is childless by definition, a template's children hang off a content fragment, foreign content is not ours to judge, and an element spelling any attribute was written for a reason. That last one is what keeps <script src>, <iframe src> and <div id=mount>, each of which html-minifier-terser drops; the table adds the elements whose bare form is still doing a job, including the table structure, where dropping a cell shifts every one after it.
The check sat inside the quoted-value branch, so `<style type=text/css>` kept its marker while `<style type="text/css">` lost it. Hoisted above that branch, where the raw value is already known either way. Also backtick `@swc/html` in the schema description: bare, it reads as a JSDoc tag and truncates the generated sentence at that word.
Only implied ones were transparent before, so a page that spelled the wrappers kept every one of them. §13.1.2.4 gives each start tag its own condition; the end tags join the tables already there, with `</head>` sharing caption's rule. Both halves must hold before either goes. Two things the conditions read that the spec's prose does not spell out: whitespace the minifier is certain to drop cannot block anything, so `</head>` reads past the newline every pretty-printed page has after it; and the elements that block a `<body>` start tag are derived from HEAD_ELEMENTS rather than from the five §13.1.2.4 names, which miss `<title>` and `<noscript>` and would move both into the head. -27 bytes on html5-boilerplate and on swagger-ui.
An enumerated attribute matches its keywords ASCII-case-insensitively, so folding one changes nothing the DOM reads — the same ground the token-list and integer rewrites next to it already stand on, so it needs no option. Only a value that *is* one of the keywords folds. That is what keeps target="MyFrame" and a custom type="MyThing" exactly as written, and it is why the table carries the keyword sets rather than just the attribute names. <ol type> is left out entirely: A and a are two different keywords there, so folding one into the other renumbers the list. The table is spec prose — nothing in the IDL marks an attribute as enumerated — so a test drives every entry, and a second, hand-written one pins the entry list so a deletion cannot pass unnoticed.
Four transforms the other minifiers offer and this one did not: collapseWhitespace grows past its single mode. `true` still means "conservative" and still never removes whitespace; "smart" also drops what sits against a block element's edge, where no line box reaches it, and "all" drops every text node's edges. "smart" reads a block-level table from §15's rendering stylesheet, and only looks forward — a block sibling *behind* the whitespace would let it go too, but finding one costs a scan of the whole child list, so it keeps a space rather than pay that. preserveComments names comments to keep on top of the ones minifying always keeps. removeEmptyElements now also drops a void element that belongs in the head, derived as HEAD_ELEMENTS intersected with VOID: with no attributes a <meta> or <link> states nothing. minifyConditionalComments minifies the markup inside a downlevel-hidden comment. The printer cannot do it where it sits — only one HTML parse runs at a time — so the bodies are collected in a walk of their own and spliced in by exact source text, never by a pattern over the output, which would find a <!--[if written inside a script.
Measured against the merge base on a 706 KB, 28000-attribute page, in separate alternating processes: the batch of new transforms cost +19% CPU. This brings that to +10%, and retained heap is unchanged throughout. The chain in `_rewriteAttributeValue` asked six tables in turn whether they knew an attribute name, and the enumerated fold had made it seven. Nearly every attribute on a page — a `data-*`, an `id`, an `aria-*`, a `role` — is in none of them, so it paid all seven misses. One generated union of those names now answers for the whole chain, which leaves those attributes cheaper than they were before any of this. Three smaller ones alongside it: the two element-keyed tables the redundancy check reads are looked up once per element rather than once per attribute, the token-list duplicate check reads spans in place instead of cutting the list up, and the structural-tag check tests the element name before anything else.
The rebase landed on top of a change that replaced `minimize: true` with `mode: "minify"` and dropped the map. Two callers this branch added still spelled the old one: the nested pass over a conditional comment's body, and six unit tests, which stopped printing rather than failing.
ea2e585 to
661d0a5
Compare
The option claimed to drop only markers nothing a selector or a script
can observe, and that is not true: `querySelector('style[type]')` can
tell one went. What actually separates the tier from "all" is narrower —
every marker in it sits on an element that renders nothing, so no rule
that styles the page stops applying, whereas "all" drops
`input[type=text]`, which stylesheets really do select on. Both the
schema description and the generated table now say that instead.
`minifyConditionalComments` parsed the document twice: once with a visitor to find the comments, then again to print. A visitor rides the same walk that prints, so the first pass was never needed — the option now costs 2% over a document that has one, rather than a second parse of every document it is enabled for. The bodies still get their own processor. The collector is registered on the document's, and a conditional comment nested in one would write into the map being read.
The second one only existed so a body could be minified without the collector visitor attached to it. A flag says the same thing: it stops recording once the document has printed, so nothing a body contains can write into the map being read.
`PrintOptions` sat in the shared SourceProcessor and enumerated both languages' entries — CSS's `convertLengthUnits` next to HTML's `sortClassNames` — so every option added to either edited a file the other depends on, and `process` copied each one across by hand. The base now carries `mode` alone and PrintContext takes the language's own type, which CSS and HTML each name once. `environment` and `convertLengthUnits` do reach the HTML minifier, and should: an inline `<style>` and every `style=""` run through the CSS minifier, so `optimization.minimize.css` rides along to reach it. They are not HTML options — the schema has never accepted either under `optimization.minimize.html` — and `HtmlPrintOptions` now says so by picking them off `CssProcessOptions` instead of restating them.
`lint:types-test` runs tsc over test/, and neither annotation was there: the mode was widened to `string`, which stopped matching the option's union and resolved `process` to no overload at all.
Omitting them relies on §13.1.2.4 tag inference, which is a guarantee of a browser's parser and not of everything that reads HTML — an email client, a template engine, a post-processor matching on the output. A page that spells the wrappers keeps them again; a parser-implied one is still printed without them, as it was before. Reverts the transform, its tables (BODY_START_TAG_BLOCKERS, OPTIONAL_END_TAG_UNLESS_COMMENT, and `head` in the caption rule) and the whitespace-lookahead the `</head>` condition needed. Gives back the 27 bytes it saved on html5-boilerplate and on swagger-ui.
Only a transform nothing can observe stays unconditional. Dropping a redundant attribute and folding a run of adjacent <style> both change what the engine builds, so each is now an option that is off by default (`removeRedundantAttributes`, `mergeStyles`). A repeated token goes only from a list the DOM reflects as a DOMTokenList, and an enumerated value folds only where the IDL member is limited to only known values, so `target` / `formtarget` / <area shape> / <textarea wrap> keep their case. Also fixes the newline after an empty <pre> / <textarea>: the swallow offer stood until the next text token instead of the next token. The browser-equivalence suite now covers all of it — it compares the value each attribute reflects, and checks every enumerated keyword against the engine rather than only the ones a fixture carries.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.