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

🐛 BUG: [AST] style tag is moved inside the html tag #585

Closed
mrienstra opened this issue Oct 23, 2022 · 1 comment · Fixed by #587
Closed

🐛 BUG: [AST] style tag is moved inside the html tag #585

mrienstra opened this issue Oct 23, 2022 · 1 comment · Fixed by #587

Comments

@mrienstra
Copy link

mrienstra commented Oct 23, 2022

Version I'm using

n/a, bug is visible inside test, see below.

Describe the Bug

<html>
  <head>

  </head>
  <body>

  </body>
</html>

<style>

</style>

becomes

<html>
  <head> </head>
  <body> </body>

  <style></style>
</html>

As per withastro/prettier-plugin-astro#295 & withastro/prettier-plugin-astro#260 (comment)

The first step would be changing internal/printer/printer_test.go#L2548 from:

{
  {Type: "element", Name: "html", Children: {
      {Type: "element", Name: "body", Children: {
          {Type: "element", Name: "h1", Children: {
              {Type: "text", Value: "Hello world!"}
            }
          }
        }
      },
      {Type: "element", Name: "style"}
    }
  }
}

to:

{
  {Type: "element", Name: "html", Children: {
      {Type: "element", Name: "body", Children: {
          {Type: "element", Name: "h1", Children: {
              {Type: "text", Value: "Hello world!"}
            }
          }
        }
      }
    }
  },
  {Type: "element", Name: "style"}
}

Or, without formatting, from:

want:   []ASTNode{{Type: "element", Name: "html", Children: []ASTNode{{Type: "element", Name: "body", Children: []ASTNode{{Type: "element", Name: "h1", Children: []ASTNode{{Type: "text", Value: "Hello world!"}}}}}, {Type: "element", Name: "style"}}}},

to:

want:   []ASTNode{{Type: "element", Name: "html", Children: []ASTNode{{Type: "element", Name: "body", Children: []ASTNode{{Type: "element", Name: "h1", Children: []ASTNode{{Type: "text", Value: "Hello world!"}}}}}}}, {Type: "element", Name: "style"}},
@mrienstra
Copy link
Author

You can also replicate this in the withastro/astro codebase, first remove these lines from .prettierignore:

# Ignoring these files for now due to https://github.com/withastro/compiler/issues/318
examples/basics/src/layouts
examples/blog/src/layouts
examples/with-nanostores/src/layouts

Then, run pnpm run format, and you'll see this issue in these files:

  • examples/basics/src/layouts/Layout.astro
  • examples/with-nanostores/src/layouts/Layout.astro

natemoo-re added a commit that referenced this issue Oct 24, 2022
* fix(#585): followup to fix style tag moving inside html

* chore: remove change from diff

* chore: update test

* chore: add changeset

Co-authored-by: Nate Moore <[email protected]>
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

Successfully merging a pull request may close this issue.

1 participant