Repository navigation
🐛 fix(minify): keep end tags a stripped comment hides - #2184
Merged
gaborbernat merged 5 commits intoNov 15, 2026
Merged
Conversation
Minifying the minified output again could change it, so minify was not a fixed point. Two causes: - A stripped comment reset the walk's trailing-formatting state, so an ancestor end tag was dropped that the reparse needs once the formatting element is the last content. - The body start tag was dropped before base, basefont, bgsound, noframes, noscript and title. The parser files those elements under head, which changed the tree. Refs tox-dev#2182
Merging this PR will not alter performance
Comparing Footnotes
|
…idempotent # Conflicts: # src/turbohtml/_c/serialize/minify.c # tests/serialize/test_minify.py
The parser drops the newline that opens a pre or listing. When a stripped comment came before the text, the minifier looked at the comment as the first child, did not write the newline the reparse needs, and re-minifying changed the output. The leading-newline check now reads the first content child, skipping stripped comments. The other serializers keep their first-child check. Refs tox-dev#2182
The leading-newline check ran for every element before its tag test. Only pre, textarea and listing need it, so the comment skip now sits behind that test. Refs tox-dev#2182
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
minifyis documented as idempotent, but minifying its own output could change the document. 🔁 Once this merges, a second pass returns minified output unchanged, so pipelines that minify more than once get stable results. Fixes #2182.The minifier drops comments and some tags that the HTML parser would rebuild anyway. In two places it dropped a comment and then decided as if the comment were still there, so the output lost a tag or a newline the reparse needs. The serializer now skips stripped comments when it makes those decisions.
Behavior changes
preorlistingwhose first text starts with a newline after a stripped comment, since the parser drops that newline.Output differs from before only in those two cases.