Skip to content

Clarify information about deprecation of :ng-deep and recommend replacement #25160

Closed

Description

@cvmocanu

The documentation at https://angular.io/guide/component-styles states this about :ng-deep:

The shadow-piercing descendant combinator is deprecated and support is being removed from major browsers and tools. As such we plan to drop support in Angular (for all 3 of /deep/, >>> and ::ng-deep).

As I understand, Angular was using the browser support for the piercing selectors /deep/ and >>>.

But :ng-deep is surely not supported by any browser.
And this is what I find confusing in the documentation. I don't understand what browser support has anything to do with :ng-deep.

The way I understand it, :ng-deep prevents Angular from appending the attribute selectors to all selector following it.

So, this CSS in a component:

:host ::ng-deep .my-button .ui-button-text {
    font-weight: bold;
}

will be transformed to:

[_nghost-c12]     .my-button .ui-button-text {
    font-weight: bold;
}

Without :ng-deep, this will be produced instead:

[_nghost-c12]     .my-button[_nghost-c12] .ui-button-text[_nghost-c12] {
    font-weight: bold;
}

(obviously breaking my intention).

I find 2 problems with the documentation, as it stands now:

  • I don't see any relationship between lack of browser support for piercing selectors and deprecating :ng-deep
  • I don't see any reason to deprecate :ng-deep (since it just tells Angular: "keep your attribute selectors away from my styles")

I propose the following:

  • if I missed anything, and there is a valid reason why :ng-deep should be deprecated, the documentation should be changed to explain why
  • if my reasoning above is correct, remove the section about deprecating :ng-deep, keeping the deprecation notice only for the piercing selectors /deep/ and >>>.

Activity

  1. changed the title [-]fix confusing documentation about ::ng-deep[/-] [+]fix confusing documentation about :ng-deep[/+] on Jul 27, 2018
  2. trotyl commented on Jul 27, 2018

    @trotyl
    Contributor

    Duplicate of #17867.

    :ng-deep is only used to provide deprecating stage, allowing user to drop this usage with a forgiving time period. It's never a designed new feature of Angular.

    :ng-deep is indeed not supported by browser, that's why it shouldn't be supported by Angular in the first place.

  3. cvmocanu commented on Jul 27, 2018

    @cvmocanu
    Author

    :ng-deep is indeed not supported by browser, that's why it shouldn't be supported by Angular in the first place.

    I fail to see the logic in this.
    :ng-deep doesn't need browser support. It only needs Angular pre-processing support, and we already have this.

  4. trotyl commented on Jul 27, 2018

    @trotyl
    Contributor

    @cvmocanu The ViewEncapsulation.Emulated is an exact shim of Shadow DOM behavior, there won't be any so-called Angular rule for that.

  5. cvmocanu commented on Jul 27, 2018

    @cvmocanu
    Author

    I guess I need to do some reading on the Shadow DOM.

    It looks to me that the people on the Shadow DOM standards commission just deprecated a useful feature, without providing an alternative :(

  6. pauldraper commented on Jul 27, 2018

    @pauldraper
    Contributor

    @trotyl #17867 had no resolution.

    Angular seems confused by whether it wants to offer Angular features or be a compatibility layer for W3C specs drafts (which are a constantly moving target, making Angular an unstable platform).

  7. added this to the needsTriage milestone on Jul 31, 2018
  8. jenniferfell commented on Aug 9, 2018

    @jenniferfell
    Contributor

    Looks like the resolution for #17867 (thanks for the link, @trotyl ) is to watch #23636. This seems to be an open question of what the Angular platform supports, and that issue contains the discussion.

    I believe the documentation is, for now, correct and complete:

    "The shadow-piercing descendant combinator is deprecated and support is being removed from major browsers and tools. As such we plan to drop support in Angular (for all 3 of /deep/, >>> and ::ng-deep). Until then ::ng-deep should be preferred for a broader compatibility with the tools."

    When we have more information about the replacement options, we will publish them.

  9. jenniferfell commented on Aug 9, 2018

    @jenniferfell
    Contributor

    @IgorMinar When you get a chance, is my assessment above correct? Is there anything we can or should add now to the documentation here: https://angular.io/guide/component-styles#deprecated-deep--and-ng-deep

    Thank you.

  10. 102 remaining items

  11. added this to the v18-candidates milestone on Feb 21, 2024
  12. removed this from the v18-candidates milestone on Feb 21, 2024
  13. added this to the Backlog milestone on Feb 27, 2024
  14. alxhub commented on Mar 22, 2024

    @alxhub
    Member

    As (sort of) announced at ng-conf, ng-deep is no longer labeled as deprecated in the angular.dev docs. We will not be removing the feature (not that we had planned to anyway). However, we still discourage its use, as we view ng-deep as a CSS anti-pattern in many cases, similar to e.g. !important.

  15. Jordan-Hall commented on Mar 22, 2024

    @Jordan-Hall
    Contributor

    That's a really bad decision. Even if you don't remove it :( people will just use and abuse it. So many clients abused the feature as it is

  16. diegovilar commented on Mar 22, 2024

    @diegovilar

    I think that keeping it is the right call. Removing it would be like removing !important from CSS. It's a last resource, but sometimes it is the ONLY way we can customize something we did not author ourselves and the ppl who did did not include extension points

  17. dalenguyen commented on Mar 23, 2024

    @dalenguyen

    Agree, especially for something like Material Overlay CDK. Without ng-deep, the custom styling would end up in global styles.

  18. pauldraper commented on Mar 23, 2024

    @pauldraper
    Contributor

    We will not be removing the feature (not that we had planned to anyway).

    Somehow, for some reason, Yyars of conversation assumed otherwise ^

    Communication is key.

  19. angular-automatic-lock-bot commented on Apr 23, 2024

    @angular-automatic-lock-bot

    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.

  20. locked and limited conversation to collaborators on Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P4A relatively minor issue that is not relevant to core functionsarea: docsRelated to the documentationcanonicalThis issue represents a canonical design issue in Angular.freq1: low

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions