-
Notifications
You must be signed in to change notification settings - Fork 26.4k
fix(platform-browser): Fixes Shadowdom encapsulation to not include external styles #62357
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
base: main
Are you sure you want to change the base?
Conversation
… that are not declared by the component. Prevents style bleed, so components are scoped correctly. Now adheres to the spec for Shadowdom
Also, even if this could considered a fix (to respect the spec), the fact the applications can have relied on the current implementation, changing the behavior is a breaking change as such cannot land in a minor. (see https://www.hyrumslaw.com/) |
No problem 😊 I mean that's kind of on them for misusing the purpose of the shadowdom 😂 but I take your point Seeing as you cannot predict what additional stylesheets were getting inserted into the component before, I'd be amazed (actually horrified) if people have built ui around expecting things to be there that shouldn't be. I'll take a nosey at the tests later on, ran the tests for platform-browser before and they passed, so will dig into the failures Edit - I have updated tests and added extra test cases, marked as breaking change |
BREAKING CHANGE: Fixes Shadowdom to not include external styles that are not declared by the component. Prevents style bleed, so components are scoped correctly. Now adheres to the spec for Shadowdom. Adds test cases.
Refactor of test cases to not use content projection. Sets up child components of shadow component.
This commit removes a log that I left in by mistake
This commit updates expected defer uncompressed main size
I ran a global test on Google's codebase and confirm that this is a breakage change that we won't land outside of a breaking change window. |
No problem, that makes sense. Thanks for verifying. I've fixed the lint issue and the integration test btw that was checking the bundle size. I'm curious @JeanMeche - what was the issue in the codebase? Were some shadowdom components relying on global styles (that were previously being inserted into the shadowdom)? |
Fixes Shadowdom encapsulation to not include external styles that are not declared by the component. Prevents style bleed, so components are scoped correctly. Now adheres to the spec for Shadowdom
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: 57801
The current Shadowdom implementation is incorrect, and does not adhere to the spec. Shadowdom components should be encapsulated with no style leakage, but currently, external styles are added that are completely unrelated to the shadow component. This causes significant bloat.
Before:
After:
What is the new behavior?
The new behaviour removes the
sharedStylesHost
from the domrenderer for ShadowDom. There should be NO shared styles polluting the shadowdom.Does this PR introduce a breaking change?
Now that it follows the spec, shadowdom does not now add
<style>
tags unrelated/not imported/defined by the component. If someone has built ui off of (incorrectly) expecting styles not imported by the shadow component to be there, they will need to update their components to declare the necessary styles for that component.Other information
I have tested this in an enterprise application (over 6000 components), with multiple shadowdom components - each use of one of these components previously added ~50kb bloat, per component. After this change, only the styles that have been declared inside the component are added to it, fixing the bug and making Angular's shadowdom implementation adhere to the spec.
Ideally this would be available as a patch version in both
v19
andv20
Your own documentation is currently slightly at odds with the current behaviour. This fix will make the documentation accurate/correct.