CSS Scoped and CSS Modules use encapsulation techniques either at compile-time or runtime to manage CSS isolation #2861
codecsrayo
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
There have been several approaches to styling/CSS encapsulation created by the Leptos community, which you can see here. This is not something I plan to bring into the core of the library, since it is pretty straightforward to do in userland, and this is a relatively unopinionated framework compared to the opinionated scoped styling approached you'll see in Angular/Vue/Svelte. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How It Works Internally
CSS Scoped and CSS Modules use encapsulation techniques either at compile-time or runtime to manage CSS isolation:
CSS Scoped: Astro’s compiler generates CSS that is specific to each component, applying styles only within the context of that component. This prevents collisions because the CSS is treated as part of the component, and styles do not leak outside of their intended scope.
CSS Modules: During the compilation of CSS files, modules generate unique class names associated with the specific module. This is typically done through hashing class names to ensure their uniqueness, preventing clashes with other styles in the application.
Both methods help keep CSS organized and isolated, making component development more predictable and manageable.
Why Implement These Methods in Leptos
Implementing CSS Scoped or CSS Modules in Leptos would be beneficial for several reasons:
Encapsulation: Ensures that styles defined in one component do not unintentionally affect other parts of the application, improving modularity and reducing styling conflicts.
Maintainability: By isolating styles to their respective components or modules, it becomes easier to manage and update styles without worrying about side effects or conflicts.
Scalability: As applications grow and more components are added, having well-encapsulated CSS helps in maintaining a clean and organized codebase, which is crucial for large projects.
Predictability: Scoped styles and unique class names reduce the risk of unexpected styling issues, making it easier to reason about how styles are applied and where they come from.
Incorporating these techniques in Leptos would align with modern best practices for component-based development, promoting better design patterns and improving the overall developer experience.
Beta Was this translation helpful? Give feedback.
All reactions