Skip to content

fix: match class and style directives against attribute selector #16179

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

Merged
merged 1 commit into from
Jun 17, 2025

Conversation

7nik
Copy link
Contributor

@7nik 7nik commented Jun 16, 2025

Closes #16162

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Jun 16, 2025

🦋 Changeset detected

Latest commit: cf26945

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot
Copy link

Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@16179

@Rich-Harris Rich-Harris merged commit 2b20a2d into main Jun 17, 2025
14 checks passed
@Rich-Harris Rich-Harris deleted the fix-16162 branch June 17, 2025 21:53
@github-actions github-actions bot mentioned this pull request Jun 17, 2025
@24jr
Copy link

24jr commented Jun 18, 2025

Whatever you did in this change, all my buttons just turned white

@7nik
Copy link
Contributor Author

7nik commented Jun 18, 2025

These directives add class/style attribute to the element, so the attribute selectors can match them but, before this fix, could fail in some cases.
If there is a real bug - open a new issue.

@24jr
Copy link

24jr commented Jun 18, 2025

I mean just doing this it doesnt show a red background when i add a class="base" even with nothing in it but if I remove class="base" then the red shows. I dont specify background-color at all in .base and i want the conditional class to be prioritized when it its true

<button class="base" class:primary={true}>test</button>

<style>
  .base {
    outline: none;
    border: none;
  }
  .primary {
    background-color: red;
  }
</style>

@mattpilott
Copy link
Contributor

mattpilott commented Jun 19, 2025

This is breaking sites where class props are defined as undefined
let { mypropclass = undefined } = $props()
<div class:mypropclass></div>

@7nik
Copy link
Contributor Author

7nik commented Jun 19, 2025

@mattpilott I don't really get what gets broken in your example. Can you test on #16204?

@mattpilott
Copy link
Contributor

@7nik
Copy link
Contributor Author

7nik commented Jun 19, 2025

That PR fixes this repro.

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 this pull request may close these issues.

Style directive doesn't match [style] selector
4 participants