Comments (9)
As a general rule, what I do to know it is incorrect removal, is to use Developer Tools to add the new style rule. I copy and paste the alleged unused CSS selector into Developer Tools. If it works, it means it was incorrectly removed.
You can't use this method to check if it was incorrectly removed because styles are scoped in svelte. This means that in a situation like this
<!-- Parent.svelte -->
<div>
<Child />
</div>
<!-- Child.svelte -->
<span>text</span>
A selector like div > span
will work in the browser but not in Parent.svelte
. What I suspect is happening is that you are rendering a snippet inside the div so the nested style is not working but that to me seems expected. For the future try to create a minimal reproduction instead of posting the entire repo like this
Again this should be the intended behavior since the snippet is "kinda like a child component"
from svelte.
Ok ok. You're hinting something to me that is completely new to me. I don't have any recollection of reading it anywhere: Snippets inside a component are like separate components when it comes to style scoping? Did I understand it correctly?
from svelte.
Duplicate of #10143.
from svelte.
Ok ok. You're hinting something to me that is completely new to me. I don't have any recollection of reading it anywhere: Snippets inside a component are like separate components when it comes to style scoping? Did I understand it correctly?
It's not exactly the same...you can target values inside the snippet with the same style but if you render a snippet inside another element svelte will not follow through the snippet to see if inside the snippet there's a selector that will satisfy that css as I've shown in my repro.
from svelte.
Thanks a lot for the explanation. But this is a bug, correct? I was shocked because you used the adjective "expected". If it were expected, I would say it takes away the usefulness of snippets inside components.
from svelte.
Thanks a lot for the explanation. But this is a bug, correct? I was shocked because you used the adjective "expected". If it were expected, I would say it takes away the usefulness of snippets inside components.
Not exactly because you can adjust your css to target what's inside the snippet excluding the wrapper. As you can see in the duplicated issue posted by Conduitry there's a draft PR opened by Simon to try and fix this but it's not straightforward since static analysis can only get you far enough...for example what happens if you do this
{#snippet span(level=0)}
{#if level < 3}
<span>{@render span(level+1)}</span>
{/if}
{/snippet}
{@render span()}
<style>
span span span span {
color: red;
}
</style>
from svelte.
I think I understand. My point to the detriment of snippets is that they were advertised as a way to reuse code. Sveltestrap has a very good example (or even exampleS, plural). I think my sample is also a very good one where I cannot divide styles. I depend on identifying the even and odd rows in the parent markup, and then render the snippet several times with the additional classes.
Anyway, as long as you, masters of the UI understand, I'll butt out. I'm a backend dev that only enjoys UI building in Svelte. I trust that you guys will do what's best. Cheers.
from svelte.
I think I understand. My point to the detriment of snippets is that they were advertised as a way to reuse code. Sveltestrap has a very good example (or even exampleS, plural). I think my sample is also a very good one where I cannot divide styles. I depend on identifying the even and odd rows in the parent markup, and then render the snippet several times with the additional classes.
Anyway, as long as you, masters of the UI understand, I'll butt out. I'm a backend dev that only enjoys UI building in Svelte. I trust that you guys will do what's best. Cheers.
Just pass odd or even to the snippet and apply a class to the snippet element based on that?
from svelte.
Good suggestion. I don't remember if that's all that I need, but certainly, you are correct that maybe I can overcome certain things with traditional programming. 👍
from svelte.
Related Issues (20)
- False positive error: rune outside svelte HOT 1
- Bump all dependencies before final release
- Documentation Clarification for Rookies HOT 3
- Svelte 5 (5.0.0-next.167): Upgrading to the latest Svelte 5 breaks SvelteKit routing HOT 9
- Svelte 5: this type of directive is not valid on components HOT 5
- [Svelte 5] `{#if}` block with several reactive children does not re-render properly HOT 12
- Svelte 5 legacy: transition not conveyed using $$restProps and svelte:element HOT 1
- next.167 breaks <svelte:component> in development mode
- Sveltekit + Svelte 5: Navigating only loads the layout, not the page HOT 2
- Svelte 5: Mutating data in load fn stops page reactivity HOT 4
- Svelte 5: this type of directive is not valid on components HOT 4
- Svelte 5: Inaccurate Error Message HOT 1
- `batch` function to update multiple sources at once HOT 4
- Svelte 5 reporting invalid type error on Svelte 4 component using slot
- Make aria- dependencies optional HOT 9
- Svelte 5: problems unmounting elements from the dom inside an each block HOT 5
- next.168 development mode and component snippets inside loop HOT 5
- next.168 broke unmounting content in my app HOT 5
- Breakpoints cannot be set on certain locations in Svelte generated code in V8 HOT 1
- Bad compilation of valid Svelte 4 components under Svelte 5 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte.