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

Page's html and body styling still applied #68

Closed
achang97 opened this issue Jan 17, 2020 · 7 comments
Closed

Page's html and body styling still applied #68

achang97 opened this issue Jan 17, 2020 · 7 comments

Comments

@achang97
Copy link

I am building a chrome extension and am injecting code directly in the page. To avoid conflicting styles, I have utilized the react-shadow package and have been mostly successful in isolating the CSS. However, I am still getting issues with leakage of styles into the page.

For instance, in Gmail my extension looks like this:

Screen Shot 2020-01-16 at 5 30 46 PM

But in Stack Overflow it looks like this:
Screen Shot 2020-01-16 at 5 31 08 PM

I looked at the rendered HTML in the browser and it seems like there is still leakage of the styling on the html and body tags from the page into my page. Does anyone know why this might be the case?

@Wildhoney
Copy link
Owner

Inherited styles such as color, font-family etc... are still carried across the shadow boundary.

@achang97
Copy link
Author

Is there a good way of resetting these styles? I’m also trying to use Material UI within the shadow dom, which is proving to be a little difficult.

@Wildhoney
Copy link
Owner

Wildhoney commented Jan 17, 2020

Yes with all: initial (or revert – not as well supported).

@Wildhoney
Copy link
Owner

As an example: https://codesandbox.io/s/react-shadow-4rcso

@achang97
Copy link
Author

Thanks - I reset some of the styles using that approach, but with Material UI it’s still inheriting some of external page’s styling.

That is, there are styles such as the font-size (defines in the html tag) which impact the size of fonts of mui, which are defined in rem. I followed the answer provided here: https://stackoverflow.com/questions/51832583/react-components-material-ui-theme-not-scoped-locally-to-shadow-dom, but I’m still having some issues with minor differences across sites.

@Wildhoney
Copy link
Owner

Well that's problematic as rem is inherited from the html tag, and the shadow root has no effect on that inheritance.

@Wildhoney
Copy link
Owner

I’m going to close the ticket, but please let me know if you need any more help.

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

2 participants