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

feat: add lower bound encapsulation #30

Open
pemrouz opened this issue Dec 1, 2016 · 0 comments
Open

feat: add lower bound encapsulation #30

pemrouz opened this issue Dec 1, 2016 · 0 comments

Comments

@pemrouz
Copy link
Collaborator

pemrouz commented Dec 1, 2016

There are two types of CSS encapsulation the shadow DOM provides: upper bound and lower bound. For browsers that don't support shadow encapsulation, the former is easy to solve via component name prefixing. The latter is near impossible to solve in a performant way. This is why I've generally been advising to use the child (>) selector over the descendent ( ) selector to avoid leaking styles to children. Components have a known structure and it's usually very rare that authors actually intend to say "match from here to infinity". This should also be faster. In retrospect, the ubiquitous use of the descendent selector over the child selector is mostly just a product of bad habits imho.

However, there is a proposal in vercel/next.js#249 that would potentially solve this problem in a performant way. We already transform styles AOT, but the additional concept is to tag each element with it's direct parent which would help limit applying styles to non-direct children elements.

/cc @rauchg who came up with the idea and we discussed a few aspects with.

The only thing I'm not sure about is the API surface. Ideally it should be another render middleware:

// per-component
export default encapsulate(function component(node, data){
  ..
})

// or globally
ripple.draw = encapsulate(ripple.draw)

However, need to see if would be more performant to do this at the once helper function level.

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

No branches or pull requests

1 participant