Skip to content

Commit c81076e

Browse files
committed
Summary & motivation
1 parent d6c1563 commit c81076e

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

text/0000-css-in-html.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
- Start Date: 2018-11-05
2+
- RFC PR:
3+
- Svelte Issue:
4+
5+
# CSS-in-HTML
6+
7+
## Summary
8+
9+
This is a larger RFC focused on solving CSS scoping on both a stand-alone component and global level. This RFC also proposes an approach to reactive CSS as well as better tooling for incorporating 3rd party processors and compilers.
10+
11+
## Motivation
12+
13+
Svelte developers generally acknowledge that there needs to be a better answer for CSS both in components as well as a larger ecosystem consideration. There are varities of opinions about best methodologies for CSS. This proposal sidesteps opinions as much as possible, allowing developers to work with whatever framework or method best suits their purposes, yet cherrypicking the best design considerations.
14+
15+
One debate often boils down to scoping considerations. Currently, with Svelte 2, the inclusion of any CSS within a style tag is considered 100% scoped. Consider:
16+
17+
```html
18+
<!-- main component -->
19+
<div>
20+
<CascadingDiv/>
21+
</div>
22+
<style>
23+
div { color: goldenrod; }
24+
</style>
25+
<script>
26+
export default {
27+
components: { CascadingDiv: './cascasing-div.html' }
28+
};
29+
</script>
30+
```
31+
32+
```html
33+
<!-- component: cascasing-div.html <CascadingDiv/> -->
34+
<div>This is not goldenrod. Styles do not cascade!</div>
35+
```
36+
37+
The only way out of this is to wrap your selector(s) in `:global()`. This, however, gets to be fairly verbose when you want to wrap all selectors on the page.
38+
39+
```html
40+
<style>
41+
:global(.foo) { text-align: center; }
42+
:global(.foo span) { font-size: 80%; }
43+
:global(.foo em) { color: pink; }
44+
.bar { text-align: right; }
45+
<!-- unscoped: `.foo *` -->
46+
<!-- scoped: `.bar` -->
47+
</style>
48+
```
49+
50+
Arguably, the appeal of single file components is encapsulating all component-relatives into the single file. But the above also has the sometimes unwanted effect of cascading everywhere. This presents the complex challenge of controlling scope to a single component, a set of embedded components, or global.
51+
52+
It would be nice if there was a simple mechanism for controlling scope more easily at a component level, making JS variables behave dynamically in CSS and HTML, as well as passing style scopes from component to embedded component if necessary.
53+
54+
## Detailed design
55+
56+
> This is the bulk of the RFC.
57+
58+
> Explain the design in enough detail for somebody
59+
familiar with the framework to understand, and for somebody familiar with the
60+
implementation to implement. This should get into specifics and corner-cases,
61+
and include examples of how the feature is used. Any new terminology should be
62+
defined here.
63+
64+
## How we teach this
65+
66+
> What names and terminology work best for these concepts and why? How is this
67+
idea best presented? As a continuation of existing Svelte patterns, or as a
68+
wholly new one?
69+
70+
> Would the acceptance of this proposal mean the Svelte guides must be
71+
re-organized or altered? Does it change how Svelte is taught to new users
72+
at any level?
73+
74+
> How should this feature be introduced and taught to existing Svelte
75+
users?
76+
77+
## Drawbacks
78+
79+
> Why should we *not* do this? Please consider the impact on teaching Svelte,
80+
on the integration of this feature with other existing and planned features,
81+
on the impact of the API churn on existing apps, etc.
82+
83+
> There are tradeoffs to choosing any path, please attempt to identify them here.
84+
85+
## Alternatives
86+
87+
> What other designs have been considered? What is the impact of not doing this?
88+
89+
> This section could also include prior art, that is, how other frameworks in the same domain have solved this problem.
90+
91+
## Unresolved questions
92+
93+
> Optional, but suggested for first drafts. What parts of the design are still
94+
TBD?

0 commit comments

Comments
 (0)