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 in config don't work as expected #8496

Closed
1 task
lubowiecki opened this issue Sep 11, 2023 · 3 comments
Closed
1 task

compressHTML in config don't work as expected #8496

lubowiecki opened this issue Sep 11, 2023 · 3 comments
Labels
needs response Issue needs response from OP

Comments

@lubowiecki
Copy link

lubowiecki commented Sep 11, 2023

Astro Info

"Astro                    v3.0.12\nNode                     v18.15.0\nSystem                   Windows (x64)\nPackage Manager          pnpm\nOutput                   static\nAdapter                  none\nIntegrations             @astrojs/tailwind\n                         @astrojs/sitemap"

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

I have this config:

import { defineConfig } from "astro/config";
import tailwind from "@astrojs/tailwind";
import sitemap from "@astrojs/sitemap";

// https://astro.build/config
export default defineConfig({
  site: "https://www.reksio-wet.pl",
  integrations: [tailwind(), sitemap()],
  compressHTML: true,
});

and this file index.astro:

<html>
  <head></head>
  <body>
    <p>
      Lorem ipsum dolor sit, amet consectetur adipisicing elit. Sint facere 
      inventore nulla explicabo libero delectus voluptatibus, 
      est, ut fugiat recusandae quam, iste natus. 
      Iste, non minus. Beatae sit nisi sint!
    </p>
  </body>
</html>

When I run astro build I get this file in dist folder:

<!DOCTYPE html><html><head><link rel="stylesheet" href="/_astro/rodo.d2d0dbb6.css" /></head><body><p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Sint facere 
      inventore nulla explicabo libero delectus voluptatibus, 
      est, ut fugiat recusandae quam, iste natus. 
      Iste, non minus. Beatae sit nisi sint!
</p></body></html>

What's the expected result?

dist/index.html

<!DOCTYPE html><html><head><link rel="stylesheet" href="/_astro/rodo.d2d0dbb6.css" /></head><body><p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Sint facere inventore nulla explicabo libero delectus voluptatibus, est, ut fugiat recusandae quam, iste natus. Iste, non minus. Beatae sit nisi sint!</p></body></html>

Link to Minimal Reproducible Example

https://stackblitz.com/edit/stackblitz-starters-qesr2a?file=dist%2Findex.html

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Sep 11, 2023
@lubowiecki lubowiecki changed the title compressHTML in config don't work compressHTML in config don't work as expected Sep 11, 2023
@ematipico
Copy link
Member

ematipico commented Sep 11, 2023

That's not a bug, it's intentional. Newlines and white spaces inside HTML tags have a meaning actually, You can check this issue, which provides more background: withastro/compiler#815

@ematipico ematipico added needs response Issue needs response from OP and removed needs triage Issue needs to be triaged labels Sep 11, 2023
@matthewp
Copy link
Contributor

Closing, the intent of this feature is not to make every page output to be only 1 line.

@alexander-lozovsky
Copy link

@matthewp if it is expected behaviour, maybe worth updating docs https://docs.astro.build/en/reference/configuration-reference/#compresshtml? Because now it says "By default, Astro removes all whitespace from your HTML, including line breaks, from .astro components".

Right now I'm updating an app from Astro v2.8.0 to v3.6.4, and facing some issues due to breaking changes in compressHTML handling. Astro v3 preserve line breaks in .astro components, while v2 doesn't

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

No branches or pull requests

4 participants