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

fix: CSS adjacent and general sibling combinator treats slots as if they don't exist #8422

Merged
merged 9 commits into from
May 4, 2023

Conversation

ngtr6788
Copy link
Contributor

@ngtr6788 ngtr6788 commented Mar 25, 2023

Fixes #8284.

The problem is that the <slot> element is treated as an actual element, and for this purpose, we have to treat them as if they don't exist. More specifically, we treat all slot fallback children nodes on the same level as the slot's non-slot siblings.

[edit: I wasn't aware of the <slot> element in web components before, so I added a check that if the node belongs to a web component, we still treat slots as if they exist.]

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.

Tests

  • Run the tests with npm test and lint the project with npm run lint

@vercel
Copy link

vercel bot commented Mar 25, 2023

@ngtr6788 is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

@dummdidumm
Copy link
Member

I'm not 100% sure if we want to always do this. In the case of custom elements this element actually exists.

@ngtr6788
Copy link
Contributor Author

ngtr6788 commented Mar 28, 2023

Interesting! I am not aware of nor am familiar with web components before. Do you know what the expected behaviour would be? For example, from the bug report,

<h1>test</h1>
<slot><span>Hello</span></slot>

<svelte:options tag="my-element" />

<style>
  h1 + span {
    color: red;
  }
</style>

does h1 + span pick up the Hello, if this were a custom component?

[EDIT:]
To answer my own question, the answer is no. However, in a custom web component, h1 + slot > span does pick up the default (ie. <span>Hello</span>). Sorry for asking

@ngtr6788 ngtr6788 requested a review from tanhauhau April 14, 2023 16:19
@benmccann benmccann added this to the 3.x milestone Apr 19, 2023
@ngtr6788 ngtr6788 requested a review from benmccann April 20, 2023 19:31
@dummdidumm dummdidumm modified the milestones: 3.x, 4.x Apr 28, 2023
@dummdidumm dummdidumm changed the base branch from master to version-4 April 28, 2023 15:24
@dummdidumm dummdidumm merged commit c036396 into sveltejs:version-4 May 4, 2023
@ngtr6788 ngtr6788 deleted the css-slot-siblings branch May 11, 2023 14:15
@gtm-nayan gtm-nayan mentioned this pull request Jun 17, 2023
5 tasks
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.

CSS sibling selector to target <slot> fallback
4 participants