question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exposing a way to clone a `StyleSheet` instance

See original GitHub issue

Is your feature request related to a problem? Please describe. This would benefit use cases such as rendering multiple instances of the same Custom Element (where each instance has its own shadow root and you can’t use styles from outside the shadow root) whilst only generating styles once and then simply re-injecting them into different insertion points (one per shadow root).

Related to https://github.com/cssinjs/react-jss/issues/297.

Describe the solution you’d like I’m not sure what the best solution would be, but this potentially could be achieved via caching sheet.toString() or sheet.renderer.element.cloneNode() somehow.

I have a repro with 1000 instances of Material-UI Button component wrapped in a Custom Element here: https://codesandbox.io/s/5vx8yoooyx. You can see that displaying 1000 buttons is somewhat sluggish, and I believe it is to do with there being a lot of JSS work being redone for each button.

Are you willing to implement it? Yes.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
kofcommented, Dec 19, 2018
1reaction
kofcommented, Dec 19, 2018

Make sure to watch this https://github.com/WICG/construct-stylesheets it will fix the problem of sharing styles across shadow roots

Read more comments on GitHub >

github_iconTop Results From Across the Web

Encapsulating Style and Structure with Shadow DOM
To add a shadow root (the base node/document fragment of the shadow tree), we need to call our element's attachShadow method:
Read more >
Using dynamic styling information - Web APIs | MDN
The basic style object exposes the Stylesheet and the CSSStylesheet interfaces. Those interfaces contain members like insertRule , selectorText ...
Read more >
Where to put static files such as CSS in a spring-boot project?
The static directory is served from / . For example, src/main/resources/static/signin.css will be served from /signin.css whereas src/ ...
Read more >
How to clone a website - YouTube
With a little knowledge of HTML and CSS, you can get a head-start by cloning an existing site. Just make sure you use...
Read more >
Shadow DOM styling - The Modern JavaScript Tutorial
Shadow DOM may include both <style> and <link rel="stylesheet" href="… ... For instance, we're making <custom-dialog> element that should be ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found