Another approach to bootstrap Angular under a shadow root#67947
Merged
kirjs merged 5 commits intoangular:mainfrom Apr 10, 2026
Merged
Another approach to bootstrap Angular under a shadow root#67947kirjs merged 5 commits intoangular:mainfrom
kirjs merged 5 commits intoangular:mainfrom
Conversation
7f43620 to
6a60524
Compare
mattrbeck
reviewed
Apr 3, 2026
1a26eab to
9aa4472
Compare
mattrbeck
reviewed
Apr 6, 2026
d3b12b8 to
c722bdf
Compare
mattrbeck
approved these changes
Apr 6, 2026
Contributor
thePunderWoman
left a comment
There was a problem hiding this comment.
AGENT: Thanks for the updates! I've left a comment regarding a potential duplication of server-rendered styles when components are created in the light DOM for your consideration.
590b312 to
304ffbf
Compare
…` with a dedicated `InjectionToken` This allows code in `@angular/core` to inject and use `SharedStylesHost`, even though the implementation is defined in `@angular/platform-browser`.
This is necessary for an `RNode` to discover whether it is within the context of a shadow root, which is needed to know where a component's style should be placed. The method is Baseline Widely Available, however we need to treat it as optional for SSR / JSDom contexts where shadow DOM is not supported.
…iple times This shouldn't have been happening before, but now that we're going to start calling `addHost` during root component boostrap, we may call `addHost` on the same node multiple times and don't want to duplicate styles.
…dow roots This is a minimal implmentation which just focuses on registering parent shadow roots in `SharedStylesHost` correctly. We don't currently reference count usage of host values, meaning that as soon as we call `removeHost`, all styles are removed from it, even if other components relied on them. Therefore there is no good way to know whether styles are still needed or not, leaving us with the choice of either leaking them longer than necessary or destroying them while another component still needs them. The compromise I'm using here is to delete styles when destroying a component under a shadow root (based on the assumption that only one component will exist per shadow root) and to leave styles when destroying a component in the main document (based on the assumption that dialogs being destroyed should not impact the main application). Neither assumption is totally safe to make, but we're hoping this is a viable balance for the moment. In the future we should look into lifting these restrictions to better support those use cases while properly reference counting usage of hosts in `SharedStylesHost`. I also added some small tests to confirm that SSR styles are not duplicated, as an earlier implementation accidentally duplicated them. This should ensure we don't repeat that mistake.
…der shadow roots This tests bootstrapping Angular underneath a shadow root and that styles are applied and removed at the correct locations.
304ffbf to
e4bbecc
Compare
Contributor
|
Can you see if the presubmit failures are real? |
Contributor
Author
|
They are, but I have a separate fix for them and am planning to follow up immediately after the sync CL lands. |
Contributor
|
This PR was merged into the repository. The changes were merged into the following branches:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(Attempt number 3 at a minimal approach to supporting bootstrapping under a shadow root.)
This is a spin off of #66782, with the primary takeaway that referencing counting usages of specific shadow root hosts is hardTM. This approach attempts to avoid that problem by simply limiting to one root component per shadow root. It's not particularly elegant, but hopefully a small improvement to current behavior.
CARETAKER NOTE: Presubmit is showing a known failure in an internal app. I recommend syncing this into g3 in its own CL and let me know as I'll need to follow up with a couple prepared fixes for some internal customers.