Skip to content

fix(format/html): break if >2 children, and at least one is not whitespace sensitive#8833

Merged
dyc3 merged 1 commit intonextfrom
dyc3/html-force-break-nontext-and-blocklike
Jan 23, 2026
Merged

fix(format/html): break if >2 children, and at least one is not whitespace sensitive#8833
dyc3 merged 1 commit intonextfrom
dyc3/html-force-break-nontext-and-blocklike

Conversation

@dyc3
Copy link
Contributor

@dyc3 dyc3 commented Jan 22, 2026

Summary

This fixes formatting for the following snippet:

-<div>a<div>b</div> c</div>
+<div>
+  a
+  <div>b</div>
+  c
+</div>

Admittedly, it's not an ideal fix. The ideal fix would involve treating display: none as externally whitespace sensitive.

fixes #4927
fixes #6407

Test Plan

Improved prettier snapshots
Added some of our own snapshot tests

Docs

@changeset-bot
Copy link

changeset-bot bot commented Jan 22, 2026

🦋 Changeset detected

Latest commit: 997299f

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

This PR includes changesets to release 14 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch
@biomejs/prettier-compare 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

@github-actions github-actions bot added A-Formatter Area: formatter L-HTML Language: HTML and super languages labels Jan 22, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 22, 2026

Merging this PR will not alter performance

✅ 3 untouched benchmarks
🆕 1 new benchmark
⏩ 152 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 html_analyzer[index_1033418810622582172.html] N/A 398.2 µs N/A

Comparing dyc3/html-force-break-nontext-and-blocklike (997299f) with next (cb112ce)

Open in CodSpeed

Footnotes

  1. 152 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@dyc3 dyc3 marked this pull request as ready for review January 22, 2026 20:12
@dyc3 dyc3 requested review from a team January 22, 2026 20:12
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

Walkthrough

This PR fixes HTML formatter whitespace handling for block-like elements. The changes enhance the formatting logic in element_list.rs to correctly handle scenarios where block-like elements appear adjacent to text nodes. When multiple children exist and at least one is block-like, the formatter now emits hard line breaks and sets appropriate flags. Updates include CSS display utility comments, new test cases, and a changelog entry documenting the behaviour change.

Possibly related PRs

Suggested reviewers

  • ematipico
  • chansuke
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: forcing breaks when elements have more than two children and at least one is not whitespace-sensitive.
Description check ✅ Passed The description provides clear motivation with before/after code examples, links to fixed issues (#4927, #6407), and explains the test plan and limitations.
Linked Issues check ✅ Passed The PR implements the core fix for both linked issues by correcting HTML formatter behaviour when handling whitespace-sensitive elements, as demonstrated by the updated formatting of
a
b
c
.
Out of Scope Changes check ✅ Passed All changes are focused on the HTML formatter's whitespace handling. The changelog entry, skill documentation, and test files are all directly related to the fix scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

@dyc3 dyc3 merged commit 375792e into next Jan 23, 2026
16 checks passed
@dyc3 dyc3 deleted the dyc3/html-force-break-nontext-and-blocklike branch January 23, 2026 00:57
@github-actions github-actions bot mentioned this pull request Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Formatter Area: formatter L-HTML Language: HTML and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants