Skip to content

feat(platform-browser): add viewencapsulation shadowdom for shadow dom v1 support - #19059

Closed
abraham wants to merge 1 commit into
angular:masterfrom
abraham:view-encapsulation-modern
Closed

abraham wants to merge 1 commit into
angular:masterfrom
abraham:view-encapsulation-modern

Conversation

@abraham

@abraham abraham commented Sep 5, 2017 •

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] angular.io application / infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #7856

What is the new behavior?

ViewEncapsulation.ShadowDOM will enable component encapsulation using Shadow DOM V1 instead of the current Native mode that uses Shadow DOM v0. The main changes mean using attachShadow instead of createShadowRoot and using <slot></slot> instead of <content></content>.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

The tests are failing because chromedriver is using an old version of Chrome that doesn't support Shadow DOM v1. Either ChromeDriver will have to be updated, the tests will have to be polyfilled, or something else.

ViewEncapsulation.Native should also be deprecated. I'd be happy to work on that with some guidance after all the issues with this PR are worked out.

@Toxicable

Copy link
Copy Markdown

It might have been decided somewhere else but I'm curious about the naming.
Since this is using Shadow DOM V1 what are we going to call the API that uses Shadow DOM V2, if there is one?
Maybe something like ViewEncapsulation.Native2 would be more appropriate, similar to what Renderer2 did

@abraham

abraham commented Sep 5, 2017

Copy link
Copy Markdown
Contributor Author

I felt that ViewEncapsulation.Modern was more developer friendly. If a versioned name is needed it should be ViewEncapsulation.Native1 so that it matches the version of the Shadow DOM being requested.

@IgorMinar IgorMinar added the area: core Issues related to the framework runtime label Sep 5, 2017
@vicb vicb added the feature Label used to distinguish feature request from other issues label Sep 7, 2017
@vicb vicb closed this Sep 7, 2017
@vicb vicb reopened this Sep 7, 2017
@skreborn

Copy link
Copy Markdown
Contributor

Wouldn't it be possible instead to only keep ViewEncapsulation.Native and just let Angular deal with the difference internally? What if you need support for browser that only support one or the other? Angular should default to the latest specification at all times if available, and fall back to older ones if necessary and possible.

@abraham

abraham commented Sep 11, 2017 •

Copy link
Copy Markdown
Contributor Author

Shadow DOM v0 was an experimental non-finalized standard with limited browser support. Every browser that supported it supports v1 with the exception of old Android browsers. It should be deprecated and removed from Angular.

Supporting both of them seamlessly would be difficult at best. For example if a developer wanted write a component that used slots and they wrote it in v0 they would have this

<div>
  <content id=i1 select=".foo"></content>
  <content id=i2 select="my-child"></content>
  <content id=i3></content>
</div>

Angular would have to take that template detect that it's being rendered int v1 mode and convert it to

<div>
  <slot id=s1 name=slot1></slot>
  <slot id=s2 name=slot2></slot>
  <slot id=s3></slot>
</div>

Read more about the difference in slots.

@abraham

abraham commented Sep 11, 2017

Copy link
Copy Markdown
Contributor Author

My personal preference would be to just replace v0 with v1. Especially since v0 was experimental with limited browser support that was an opt-in feature. That feels to aggressive for Angular though. Hence this PR creates it as a new code path. Another route would be after v0 is removed, deprecate the Modern name and move it back to Native.

@skreborn

Copy link
Copy Markdown
Contributor

Alright, I'm convinced. Do you think it would be a good idea to deprecate the current Native option as DeprecatedNative (or something similar) and just have Native use the v1 specification by default? An Angular version later, the old DeprecatedNative option could be removed completely. This is what happened to the I18NPipesModule (now deprecated - but still usable - as DeprecatedI18NPipesModule) when it got replaced.

@abraham

abraham commented Sep 11, 2017

Copy link
Copy Markdown
Contributor Author

I'd be 👍 with renaming Native to DeprecatedNative and implementing a new Native with v1.

@mlc-mlapis

Copy link
Copy Markdown
Contributor

@skreborn ... if we take the fact that because of actual browsers possibilities ... using of current Native is very, very rare ... so your proposal looks as a logical and smarter step ahead.

@Toxicable

Toxicable commented Sep 12, 2017 •

Copy link
Copy Markdown

This issue with the proposed solutions is breaking changes.
renaming Native -> DeprecatedNative is a breaking change.
Since people who are currently using Native would all of a sudden be swapped over to the new DOM V1 Native in which their <template> tags would no longer work

@abraham abraham changed the title feat(platform-browser): add viewencapsulation modern for shadow dom v1 support feat(platform-browser): add viewencapsulation shadowdom for shadow dom v1 support Sep 15, 2017
@abraham

abraham commented Sep 15, 2017 •

Copy link
Copy Markdown
Contributor Author

Renamed ViewEncapsulation.Modern to ViewEncapsulation.ShadowDOM and got the tests passing.

@skreborn

skreborn commented Sep 15, 2017 •

Copy link
Copy Markdown
Contributor

Hopefully the spec won't introduce any breaking changes down the line from here on out. If it does, we can still go on with ViewEncapsulation.ShadowDOM2 (although I'd like it very much if we didn't have to start versioning it).

@abraham

abraham commented Sep 18, 2017

Copy link
Copy Markdown
Contributor Author

Is there anything else I can do to move this along or just wait for a core member to review it?

@robwormald

Copy link
Copy Markdown
Contributor

Some thoughts (thanks for looking at this @abraham!)

  • note that Angular emulates slot/content elements, even in native mode (this is why we renamed to ng-content to avoid conflicts). We're working on a Custom Elements integration that will need to account for this as well, but this will involve larger (likely breaking) changes wrt how nodes are assigned etc. Let's stay away from changes to projection here.

  • Let's go with ViewEncapsulation.ShadowDom (note the casing, sorry!) as Native2 et al are confusing (Shadow DOM V1!)

  • We should probably consider if/how/when we need to change the behavior of the emulated mode, see : https://github.com/angular/angular/blob/master/packages/compiler/src/shadow_css.ts - it's largely based on https://github.com/webcomponents/webcomponentsjs/blob/4efecd7e0e/src/ShadowCSS/ShadowCSS.js, which iirc is V0 based.

  • If/when this lands, we should go ahead with the deprecation of the ViewEncapsulation.Native API (note this does not mean immediate removal)

@abraham

abraham commented Sep 26, 2017 •

Copy link
Copy Markdown
Contributor Author

@robwormald I've updated the casing. The other three points sounded like things to think about but not direct actionable items.

@cyrilletuzi

cyrilletuzi commented Nov 28, 2017 •

Copy link
Copy Markdown
Contributor

@robwormald Is there a reason that this solution which was in initial Renderer is not in Renderer2 anymore ?

@ngbot

ngbot Bot commented Jan 16, 2018

Copy link
Copy Markdown

Hello? Don't want to hassle you. Sure you're busy. But this PR has some merge conflicts that you probably ought to resolve.
That is... if you want it to be merged someday...

@abraham

abraham commented Jan 16, 2018

Copy link
Copy Markdown
Contributor Author

I'd be happy to fix up merge issues if there is some indication that my time won't be wasted.

@ngbot ngbot Bot added this to the Backlog milestone Jan 23, 2018
@ocombe ocombe removed this from the Backlog milestone Jan 23, 2018
@robwormald
robwormald self-requested a review March 13, 2018 23:51
@robwormald robwormald added this to the Backlog milestone Mar 13, 2018
@abraham

abraham commented Apr 10, 2018

Copy link
Copy Markdown
Contributor Author

@adesugbaa

Copy link
Copy Markdown

what is the status of this? Custom elements with safari requires attachShadow support...

@Thilo84

Thilo84 commented Jun 21, 2018

Copy link
Copy Markdown

Is there any update for this pull request?
I'm waiting for a working solution for the ViewEncapsulation.Native. There is currently no working polyfill for IE.
I would be very happy if this pull request could be merged soon.
Thank you very much for your effort.

@abraham abraham closed this Jul 1, 2018
@abraham
abraham deleted the view-encapsulation-modern branch July 10, 2018 23:32
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: core Issues related to the framework runtime cla: yes feature Label used to distinguish feature request from other issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.