compiler icon indicating copy to clipboard operation
compiler copied to clipboard

🐛 BUG: compressHTML whitespace

Open cdtut opened this issue 1 year ago • 4 comments

What version of @astrojs/compiler are you using?

2.7.1

What package manager are you using?

pnpm

What operating system are you using?

linux

Describe the Bug

compressHTML is removing whitespace that shouldn't be https://github.com/withastro/compiler/issues/815.

There should be space between tags with significant whitespace.

<h1>
    <span>span</span>
    <span>span</span>
</h1>

That should become <h1><span>word</span> <span>word</span></h1> not <h1><span>word</span><span>word</span></h1>. Lot of examples like this.

html-minifier-terser has conservativeCollapse option that show how to do it. Or make everything like <h1> <span>word</span> <span>word</span> </h1> to be safe and solve this everywhere.

Link to Minimal Reproducible Example

https://gitlab.com/wackbyte/astro-compress-html-removes-whitespace

cdtut avatar Apr 09 '24 02:04 cdtut

@matthewp Can it be high priority? Production build has lots of whitespace errors that can't be released.

cdtut avatar Apr 24 '24 00:04 cdtut

@matthewp Can it be high priority? Production build has lots of whitespace errors that can't be released.

You can disable compression for the time. You have the option.

ematipico avatar Apr 24 '24 04:04 ematipico

It's not very clear the expected result VS the current result, could you move them into a code block so it's more evident?

ematipico avatar Apr 24 '24 04:04 ematipico

@ematipico

Original:

<h1>
    <span>span</span>
    <span>span</span>
</h1>

Expected:

Like html-minifier-terser conservativeCollapse

<h1><span>word</span> <span>word</span></h1>

Or this way simpler but file is bigger

<h1> <span>word</span> <span>word</span> </h1>

Current:

This ignores how HTML treat whitespace.

<h1><span>word</span><span>word</span></h1>

cdtut avatar Apr 25 '24 18:04 cdtut