Skip to content

Elements shadow dom fix#24861

Closed
robwormald wants to merge 9 commits intoangular:masterfrom
robwormald:elements-shadow-dom-fix
Closed

Elements shadow dom fix#24861
robwormald wants to merge 9 commits intoangular:masterfrom
robwormald:elements-shadow-dom-fix

Conversation

@robwormald
Copy link
Copy Markdown
Contributor

@robwormald robwormald commented Jul 12, 2018

Adds a new optional parameter to the renderer.selectRootElement method:
Before:

renderer.selectRootElement(rootSelectorOrNode);
renderer.selectRootElement(rootSelectorOrNode, preserveContents?:boolean);

preserveContents defaults to false to preserve existing renderer behavior. If set to true, the renderer will not remove the existing contents of a root element when bootstrapping a component.

This is primarily useful when combined with the ViewEncapsulation.ShadowDom Renderer - the nodes are preserved, and developers can use <slot> elements to re-project the light DOM nodes.

This change had to be made to the Renderer API itself, rather than an in a specific renderer as the method is called on the default renderer, inside the view engine, rather than a renderer specific to the component: https://github.com/angular/angular/blob/master/packages/core/src/view/services.ts#L756

Fixes #24859

@mary-poppins
Copy link
Copy Markdown

You can preview 1eec884 at https://pr24861-1eec884.ngbuilds.io/.

@robwormald robwormald force-pushed the elements-shadow-dom-fix branch 2 times, most recently from 458cf2f to 525ca3e Compare July 12, 2018 21:36
@mary-poppins
Copy link
Copy Markdown

You can preview 458cf2f at https://pr24861-458cf2f.ngbuilds.io/.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many ;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of early returns. Makes the code hard to follow. Rewrite as:

if (!preserveContent) {
  el.textContent = '';
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there an extra method here?

@mary-poppins
Copy link
Copy Markdown

You can preview 525ca3e at https://pr24861-525ca3e.ngbuilds.io/.

@robwormald robwormald force-pushed the elements-shadow-dom-fix branch from 7a08d69 to 8617d87 Compare July 12, 2018 21:50
@mary-poppins
Copy link
Copy Markdown

You can preview 7a08d69 at https://pr24861-7a08d69.ngbuilds.io/.

@mary-poppins
Copy link
Copy Markdown

You can preview 8617d87 at https://pr24861-8617d87.ngbuilds.io/.

@mhevery mhevery added the area: core Issues related to the framework runtime label Jul 12, 2018
@mary-poppins
Copy link
Copy Markdown

You can preview 8d290e2 at https://pr24861-8d290e2.ngbuilds.io/.

@mary-poppins
Copy link
Copy Markdown

You can preview 8cafe35 at https://pr24861-8cafe35.ngbuilds.io/.

@robwormald robwormald force-pushed the elements-shadow-dom-fix branch from 8cafe35 to 1f5de46 Compare July 15, 2018 23:10
@mary-poppins
Copy link
Copy Markdown

You can preview 1f5de46 at https://pr24861-1f5de46.ngbuilds.io/.

@mary-poppins
Copy link
Copy Markdown

You can preview f9b7adc at https://pr24861-f9b7adc.ngbuilds.io/.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be used anywhere. Is it necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to add a number of new integration tests for native stuff, so I added it here, also to make clear that both of these APIs are DEPRECATED

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robwormald it's better to add these helper methods when we need them, otherwise lots of them go unused. Please use that rule in the future.

Copy link
Copy Markdown
Member

@gkalpak gkalpak Jul 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeof customElements !== 'undefined' could be replaced with this.supportsCustomElements (here and below).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: supportsShadowDom implies supportsCustomElements afaict.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component is not used afaict.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be toBe(), instead of toEqual(), (here and below) to be sure the node is not duplicated or something.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused.

@robwormald robwormald force-pushed the elements-shadow-dom-fix branch from 1afc17b to 41e0914 Compare July 31, 2018 22:04
@mary-poppins
Copy link
Copy Markdown

You can preview 41e0914 at https://pr24861-41e0914.ngbuilds.io/.

@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented Aug 2, 2018

@mhevery mhevery added action: merge The PR is ready for merge by the caretaker target: major This PR is targeted for the next major release labels Aug 2, 2018
@ngbot
Copy link
Copy Markdown

ngbot bot commented Aug 2, 2018

I see that you just added the PR action: merge label, but the following checks are still failing:
    failure missing required label: "PR target: *"
    pending status "google3" is pending
    pending status "code-review/pullapprove" is pending

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

Copy link
Copy Markdown
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this pr has many of unresolved review comments from @gkalpak please address.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please document the new param

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also please document the default value.

@IgorMinar IgorMinar added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: merge The PR is ready for merge by the caretaker labels Aug 3, 2018
@robwormald robwormald force-pushed the elements-shadow-dom-fix branch from 41e0914 to 0f88a25 Compare August 7, 2018 23:38
@robwormald robwormald requested a review from IgorMinar August 7, 2018 23:41
@mary-poppins
Copy link
Copy Markdown

You can preview a81d30f at https://pr24861-a81d30f.ngbuilds.io/.

@mhevery mhevery closed this in 6e828bb Aug 31, 2018
mhevery pushed a commit that referenced this pull request Aug 31, 2018
mhevery pushed a commit that referenced this pull request Aug 31, 2018
mhevery pushed a commit that referenced this pull request Aug 31, 2018
mhevery pushed a commit that referenced this pull request Aug 31, 2018
When using ViewEncapsulation.ShadowDom, Angular will not remove the child nodes of the DOM node a root Component is bootstrapped into. This enables developers building Angular Elements to use the `<slot>` element to do native content projection.

PR Close #24861
mhevery pushed a commit that referenced this pull request Aug 31, 2018
mhevery pushed a commit that referenced this pull request Aug 31, 2018
mhevery pushed a commit that referenced this pull request Aug 31, 2018
@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 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime cla: yes target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Renderer should not clear host contents when using Shadow DOM

6 participants