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: duplicate style prop for define:vars is set when another style prop is spread #1050

Open
ascorbic opened this issue Nov 6, 2024 · 0 comments
Labels
needs triage Issue needs to be triaged

Comments

@ascorbic
Copy link

ascorbic commented Nov 6, 2024

What version of @astrojs/compiler are you using?

2.10.3

What package manager are you using?

pnpm

What operating system are you using?

Mac

Describe the Bug

Normally, when setting define:vars on a style tag, an inline style prop is added to elements that sets those CSS vars. If there is an existing style prop, the var definition is concatenated to it. If however the style prop is spread from an object, the values are not concatenated, and instead a duplicate style attribute is applied causing the second attribute to be ignored.

---
import Layout from '../layouts/Layout.astro';

const props = {
	style: "background-color: green"
}

---

<Layout title="Welcome to Astro.">

<div class='box' style="background-color: blue">Inline works</div>
<div class='box' {...props}>Spread doesn't</div>
</Layout>

<style define:vars={{
	colour: "yellow"
}}>

.box {
	display: grid;
	place-items: center;
	text-align: center;
	width: 100px;
	height: 100px;
	background-color: red;
	border: 4px var(--colour) solid;
}
</style>

...generates this:

<div class="box" style="background-color: blue; --colour: yellow;" data-astro-cid-j7pv25f6>Inline works</div>
<div class="box" style="background-color: green" data-astro-cid-j7pv25f6 style="--colour: yellow;">Spread doesn't</div>

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-88jot9?file=src%2Fpages%2Findex.astro&on=stackblitz

@github-actions github-actions bot added the needs triage Issue needs to be triaged label Nov 6, 2024
@ascorbic ascorbic changed the title 🐛 BUG: inline style prop for define:vars not set when style prop is also spread 🐛 BUG: duplicate style prop for define:vars is set when another style prop is spread Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant