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

an odd and unclear behaviour when using jsx-like syntax #5558

Closed
1 task done
gustavobini opened this issue Dec 8, 2022 · 3 comments
Closed
1 task done

an odd and unclear behaviour when using jsx-like syntax #5558

gustavobini opened this issue Dec 8, 2022 · 3 comments
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@gustavobini
Copy link

What version of astro are you using?

1.6.12

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

@astrojs/[email protected] | Node.js version is 18.12.1

What package manager are you using?

[email protected]

What operating system are you using?

Mac

Describe the Bug

When using the JSX-like syntax, the behaviour is a bit odd.

Given this example,

---
const props = {
	class: "red"
}
---
<h1 class="blue" {...props}>Should I be blue or red?</h1>
<h1 {...props} class="blue">I'm neither blue or red.</h1>
<h1 {...props}>I'm red.</h1>

<style>
	.red {
		color: red;
	}

	.blue {
		color: blue;
	}
</style>

The HTML output is,

<h1 class="blue astro-HJZ3CPP6">Should I be blue or red?</h1>
<h1 class="red">I'm neither blue or red.</h1>
<h1 class="red astro-HJZ3CPP6">I'm red.</h1>

The first h1 is blue, so props.class is ignored. - This could benefit from a mention in docs, if it's intended
The second h1 is black, even though it receives the red class. - This seems like a bug
The third h1 is red. - This behaves as expected

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-qkr4u8?file=src/pages/index.astro

Participation

  • I am willing to submit a pull request for this issue.
@bluwy
Copy link
Member

bluwy commented Dec 9, 2022

I think this is similar to withastro/compiler#659. We're currently discussing how this should be treated as spreading would simply spread the props as is without accounting for the surrounding props on the element. So you could get duplicated attributes but the browser would pick the first one.

The second h1 is black, even though it receives the red class. - This seems like a bug

This seems like a different bug though so not closing this for now.

@matthewp
Copy link
Contributor

matthewp commented Dec 9, 2022

I'm surprised that (2) does not receive the hash class name but (3) does. I would almost expect (3) not too, but then again I'm not super familiar with the hash assignment code. Maybe @natemoo-re has insight here.

@matthewp matthewp added the - P3: minor bug An edge case that only affects very specific usage (priority) label Dec 9, 2022
@natemoo-re
Copy link
Member

Closing this in favor of withastro/compiler#659

@natemoo-re natemoo-re closed this as not planned Won't fix, can't repro, duplicate, stale Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

4 participants