X Tutup
The Wayback Machine - https://web.archive.org/web/20250605224011/https://github.com/angular/angular/pull/44151
Skip to content

docs(core): improve viewEncapsulation documentation #44151

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

Closed

Conversation

dario-piotrowicz
Copy link
Contributor

@dario-piotrowicz dario-piotrowicz commented Nov 11, 2021

Slighlty improve the viewEncapsulation documentation (both in code
comments and content files) to make it more clear and understandable.

See #44099 (comment)

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • 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: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@AndrewKushnir as promised 🙂

@google-cla google-cla bot added the cla: yes label Nov 11, 2021
@pullapprove pullapprove bot requested a review from atscott November 11, 2021 20:27
@AndrewKushnir AndrewKushnir added action: review The PR is still awaiting reviews from at least one requested reviewer comp: docs target: patch This PR is targeted for the next patch release labels Nov 11, 2021
@ngbot ngbot bot added this to the Backlog milestone Nov 11, 2021
@AndrewKushnir
Copy link
Contributor

@dario-piotrowicz thanks for creating this PR 👍
I'd like to ask if @petebacondarwin can take a look, since he worked with this subsystem relatively recently.


<code-example path="component-styles/src/app/quest-summary.component.ts" region="encapsulation.shadow" header="src/app/quest-summary.component.ts"></code-example>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed the example as it didn't seem beneficial to me as:

  • after my changes the introductory text above already makes clear how to apply the strategy so I don't really think actually showing it adds much here
  • in the same docs page (below) there are various examples showing the application of the encapsulation strategy, so this example again didn't seem to add much to me


<code-example path="view-encapsulation/src/app/no-encapsulation.component.ts" header="src/app/no-encapsulation.component.ts"></code-example>>

Angular adds the styles for this component as global styles to the `<head>` of the document.

**Angular also adds the styles to all shadow DOM hosts.** Therefore, the styles are available throughout the application.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was already mentioned above so I don't think there is a need to emphasise it


`ViewEncapsulation.ShadowDom` only works on browsers that have built-in support
for the shadow DOM (see [Can I use - Shadow DOM v1](https://caniuse.com/shadowdomv1)).
Not all browsers support it, which is why the `ViewEncapsulation.Emulated` is the recommended and default mode.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed "The support is still limited" to "Not all browsers support it" because as you can see in the caniuse link the support is actually pretty good I think

Comment on lines -13 to -18
/*
// #docregion encapsulation.shadow
// warning: not all browsers support shadow DOM encapsulation at this time
encapsulation: ViewEncapsulation.ShadowDom
// #enddocregion encapsulation.shadow
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed this because as mentioned in this comment I feel like it is an unnecessary example


<code-example path="component-styles/src/app/quest-summary.component.ts" region="encapsulation.shadow" header="src/app/quest-summary.component.ts"></code-example>
<div class="alert is-important">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe it should be is-helpful? 🤷‍♂️

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't all browsers that we officially support have ShadowDOM support now?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the real reason we are still defaulting to emulated is that is makes it hard to pierce theming into the components because there is not a well lit path for how to do this with ShadowDOM. I think @jelbourn has more context here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes I wrote something similar in my comment below, happy to change this to whatever is preferred 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine unless @jelbourn (or anyone else has a view).

@dario-piotrowicz dario-piotrowicz force-pushed the viewEncapsulation-docs branch 3 times, most recently from 496cbbe to fdc735e Compare November 11, 2021 21:32
@petebacondarwin petebacondarwin changed the title docs(core): improve viewEncalsulation documentation docs(core): improve viewEncapsulation documentation Nov 12, 2021
@petebacondarwin
Copy link
Contributor

@dario-piotrowicz - while I review this PR can you fix up the commit message slightly? Add some sentence casing and fix a typo:

docs(core): improve viewEncapsulation documentation 

Slighlty improve the `viewEncapsulation` documentation (both in code
comments and content files) to make it more clear and understandable.

See https://github.com/angular/angular/pull/44099#discussion_r745890903

@mary-poppins
Copy link

You can preview c902a56 at https://pr44151-c902a56.ngbuilds.io/.
You can preview 00e3081 at https://pr44151-00e3081.ngbuilds.io/.
You can preview 73bde89 at https://pr44151-73bde89.ngbuilds.io/.
You can preview 496cbbe at https://pr44151-496cbbe.ngbuilds.io/.
You can preview fdc735e at https://pr44151-fdc735e.ngbuilds.io/.

Slighlty improve the `viewEncapsulation` documentation (both in code
comments and content files) to make it more clear and understandable.

See angular#44099 (comment)
@mary-poppins
Copy link

You can preview f5c611c at https://pr44151-f5c611c.ngbuilds.io/.

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @dario-piotrowicz - definitely an improvement. I made a bunch of suggestions - mostly just stylistic.

[Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM))
to attach a shadow DOM to the component's host element, and then puts the component
view inside that shadow DOM. The component's styles are included within the shadow DOM.
The available options are:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the docs team prefer to keep an imperative feel to the docs. So probably it would be best to revert this change:

Suggested change
The available options are:
Choose from the following modes:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok 🙂 👍

but my issue here was especially that before mode made more sense as we had ShadowDom, Emulated and None, to which "mode" was more appropriate, but now we have ViewEncapsulation.ShadowDom, ViewEncapsulation.Emulated and ViewEncapsulation.None, which are actual specific value of the ViewEncapsulation enum, so I just wanted to rephrase it to indicate such.

What do you think? should I revert also the names to the old version?

@dario-piotrowicz
Copy link
Contributor Author

@petebacondarwin thanks a lot for the awesome reviewing 🙂 , sorry I made you comment that much 😓

I replied to most of you comments, I've asked follow up questions to a few, please have another look when you have the chance 🙂

@mary-poppins
Copy link

You can preview 8308abe at https://pr44151-8308abe.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 7599409 at https://pr44151-7599409.ngbuilds.io/.

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @dario-piotrowicz - LGTM!!


<code-example path="component-styles/src/app/quest-summary.component.ts" region="encapsulation.shadow" header="src/app/quest-summary.component.ts"></code-example>
<div class="alert is-important">
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine unless @jelbourn (or anyone else has a view).

@mary-poppins
Copy link

You can preview 94a6c10 at https://pr44151-94a6c10.ngbuilds.io/.

Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

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

LGTM though my knowledge in this area is limited.

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Nov 24, 2021
@ngbot
Copy link

ngbot bot commented Nov 24, 2021

I see that you just added the action: merge label, but the following checks are still failing:
    failure status "ci/circleci: legacy-unit-tests-saucelabs" is failing
    pending 1 pending code review

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.

@AndrewKushnir AndrewKushnir added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Nov 24, 2021
@AndrewKushnir
Copy link
Contributor

FYI, marking this PR as ready for merge, since we have all the necessary approvals.

Note to the Caretaker: the CI job failure is unrelated, so we can proceed with the merge.

@jessicajaniuk
Copy link
Contributor

This PR was merged into the repository by commit 6ae3858.

jessicajaniuk pushed a commit that referenced this pull request Nov 24, 2021
Slighlty improve the `viewEncapsulation` documentation (both in code
comments and content files) to make it more clear and understandable.

See #44099 (comment)

PR Close #44151
@angular-automatic-lock-bot
Copy link

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 Dec 25, 2021
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 cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
X Tutup