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: Positioning of <style> tag is inconsistent depending on the element exported by a component #408

Closed
yudai-nkt opened this issue Feb 25, 2024 · 1 comment

Comments

@yudai-nkt
Copy link

Describe the Bug

When a <style> tag is appended to an element, it basically stays the same position after formatting. If the element is <html>, however, the <style> tag will go inside the <html>.

For example,

---
---
<div>
</div>
<style>
</style>

will be formatted to

---

---

<div></div>
<style></style>

but

---
---
<html>
</html>
<style>
</style>

will be formatted to

---

---

<html>
  <style></style>
</html>

It could be that <html> element is handled differently as it represents the root of a document, but I haven't looked into the codebase yet, so I'm not sure.

Steps to Reproduce

The following packages are required for reproduction.

npm install prettier prettier-plugin-astro

Then, running the following code will show you the (seemingly) inconsistent result.

import { format } from "prettier";

const source = `
---
---
<div>
</div>
<style>
</style>
`;

console.log(
  await format(source, { parser: "astro", plugins: ["prettier-plugin-astro"] })
);

console.log(
  await format(source.replace("div", "html"), {
    parser: "astro",
    plugins: ["prettier-plugin-astro"],
  })
);
@yudai-nkt
Copy link
Author

yudai-nkt commented Feb 25, 2024

Sorry, this is a duplicate of #260 and #316 and I'll subscribe to the latter and withastro/compiler#712.

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

1 participant