Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compressHTML removes whitespace that should not be removed #7556

Closed
1 task
wackbyte opened this issue Jul 3, 2023 · 6 comments
Closed
1 task

compressHTML removes whitespace that should not be removed #7556

wackbyte opened this issue Jul 3, 2023 · 6 comments

Comments

@wackbyte
Copy link
Contributor

wackbyte commented Jul 3, 2023

What version of astro are you using?

2.7.3

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

pnpm

What operating system are you using?

Linux (NixOS)

What browser are you using?

Firefox (Librewolf)

Describe the Bug

compressHTML removes whitespace that should not be removed, even in minification. I haven't been able to determine in exactly what circumstances it does this, but it happens in both dev and production.

Here's an example:

<p>
    A
    <span>B</span>
    C
</p>
Value of compressHTML Screenshot of result
false image
true image

The whitespace is not removed if "B" is also text. I have several more examples in the repo I provided.

What's the expected result?

compressHTML should not erroneously remove whitespace.

Link to Minimal Reproducible Example

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

Participation

  • I am willing to submit a pull request for this issue.
@wackbyte
Copy link
Contributor Author

wackbyte commented Jul 3, 2023

Oh, I think this is actually a compiler issue since it's the one that does the compressing.

@wackbyte
Copy link
Contributor Author

wackbyte commented Jul 3, 2023

Reopened as withastro/compiler#815

@wackbyte wackbyte closed this as completed Jul 3, 2023
@martinburger
Copy link

Reopened as withastro/compiler#815

The fix for that has not been released yet, has it?

@wackbyte
Copy link
Contributor Author

That issue was fixed 👍

@martinburger
Copy link

I am using Astro v3.1.2

Astro                    v3.1.2
Node                     v20.7.0
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

and the following HTML code

                  <p class="card-text fw-light">Im Sommersemester 2023 leite ich
                  die beiden <a href="/veranstaltungen/">Veranstaltungen</a> <strong
                  class="fw-normal">Programmierung 2</strong> und <strong
                  class="fw-normal">Software-Entwicklungsprozesse</strong>.</p>

compiles to:

<p class="card-text fw-light">Im Sommersemester 2023 leite ich
                  die beiden <a href="/veranstaltungen/">Veranstaltungen</a><strong class="fw-normal">Programmierung 2</strong> und <strong class="fw-normal">Software-Entwicklungsprozesse</strong>.</p>

As you can see, the whitespace between </a> and <strong> is removed.

Thus, that HTML code is rendered as: Im Sommersemester 2023 leite ich die beiden VeranstaltungenProgrammierung 2 und Software-Entwicklungsprozesse.

Between Veranstaltungen and Programmierung, there should be a space character.

Any ideas what could cause that issue?

@martinburger
Copy link

martinburger commented Sep 24, 2023

Quick update: If I explicitly disable the compressHTML option, the whitespace is no longer removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants