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.

Avoid global styles to break components

See original GitHub issue

Bug Report

Describe the bug In docz-theme-default some global styles are applied which are reaching components and breaking the styles on some scenarios:

*, *:before, *:after {
    box-sizing: border-box;
  }

All my components will receive box-sizing: border-box;.

These global rules could be easily avoided by using the box-sizing properties on the necessary elements directly.

A clear and concise description of what the bug is. docz-theme-default global styles are leaking to consumer components.

To Reproduce I guess this is self explanatory.

Expected behavior Styles from docz-theme-default should not impact on consumer components.

I can provide a PR for this if maintainers think this is a valid issue.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
jedrichardscommented, Oct 29, 2018

Agreed … since this lib doesn’t make any attempt to isolate styles between the component previews and the outer theme then the very least that should happen is that global styles aren’t used in the theme.

The theme additionally includes normalize.css which can also have a global effect on component styles. It essentially forces you to use normalize.css in your apps too, since otherwise there’s no guarantee components will render consistently in docz vs. your app. It’s a shame because normalize is pretty bloated, and no longer really appropriate as a modern css reset.

Much better to make the theme CSS more robust and isolated, and reset theme elements individually as needed.

1reaction
pedronauckcommented, Nov 16, 2018

I removed normalize.css from theme default and the classes and styles applied to Playground are fixed too!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Global Styles Should be Avoided - Ben Lorantfy - Medium
Global styles should be avoided for the same reasons global variables are avoided. There's many alternatives available that enable local styling ...
Read more >
angular - How to stop global styles from affecting my component
It should be possible because Angular provides a hierarchy for the stylesheets where the global style sheet is on top of everything ...
Read more >
Avoid global styles in your Angular projects
Avoid global styles in your Angular projects · break encapsulation · poor readability · break information hiding · namespace pollution.
Read more >
Global styles should be avoided | Lorantfy Inc.
Breaks encapsulation Global styles are not encapsulated. This means if you change a global style, it can have global impacts. You'd have to ......
Read more >
Scoping CSS using Shadow DOM - Bits and Pieces
If you want to style your component using a global CSS stylesheet, you should avoid using Shadow DOM in that particular component, ...
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