The Wayback Machine - https://web.archive.org/web/20211020063742/https://github.com/angular/angular/issues/38204
Skip to content
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

Share identical stylesheets between components in the same file #38204

Closed
alxhub opened this issue Jul 23, 2020 · 2 comments
Closed

Share identical stylesheets between components in the same file #38204

alxhub opened this issue Jul 23, 2020 · 2 comments

Comments

@alxhub
Copy link
Contributor

@alxhub alxhub commented Jul 23, 2020

In rare cases, multiple components can share the same styles. For example, Material does this with MatButton and MatAnchor.

View Engine had a feature which converted styleUrls into .ngstyle.js classes with exported constants, and thus naturally deduplicated reuse of external stylesheets. Ivy does not perform this optimization by design - it was a design goal to remove all additional "shim" files.

A limited form of this optimization in Ivy is possible - within a single file, it should be possible to use the ConstantPool to deduplicate stylesheet text that is shared between multiple components. This would be useful both for external stylesheets as well as inline style text, as long as it's identical. This optimization is of course conditional on ViewEncapsulation - encapsulated and un-encapsulated styles will have different contents, and thus no reuse between them is possible.

This optimization would apply to the Material example above, since MatButton and MatAnchor are both declared in the same TS file.

@alxhub alxhub self-assigned this Jul 23, 2020
@ngbot ngbot bot added this to the Backlog milestone Jul 23, 2020
@alxhub
Copy link
Contributor Author

@alxhub alxhub commented Jul 23, 2020

The effectiveness of this operation will depend on fixing #38203, as otherwise the first component consuming a stylesheet will not benefit from extraction of a constant.

@AndrewKushnir AndrewKushnir self-assigned this Jul 23, 2020
AndrewKushnir added a commit to AndrewKushnir/angular that referenced this issue Jul 24, 2020
…e constant

Prior to this commit, duplicated styles defined in multiple components in the same file were not
shared between components, thus causing extra payload size. This commit updates compiler logic to
use `ConstantPool` for the styles (while generating the `styles` array on component def), which
enables styles sharing when needed (when duplicates styles are present).

Resolves angular#38204.
AndrewKushnir added a commit to AndrewKushnir/angular that referenced this issue Jul 24, 2020
…same file

Prior to this commit, duplicated styles defined in multiple components in the same file were not
shared between components, thus causing extra payload size. This commit updates compiler logic to
use `ConstantPool` for the styles (while generating the `styles` array on component def), which
enables styles sharing when needed (when duplicates styles are present).

Resolves angular#38204.
AndrewKushnir added a commit to AndrewKushnir/angular that referenced this issue Jul 24, 2020
…same file

Prior to this commit, duplicated styles defined in multiple components in the same file were not
shared between components, thus causing extra payload size. This commit updates compiler logic to
use `ConstantPool` for the styles (while generating the `styles` array on component def), which
enables styles sharing when needed (when duplicates styles are present).

Resolves angular#38204.
@mhevery mhevery closed this in 8e5969b Jul 27, 2020
mhevery added a commit that referenced this issue Jul 27, 2020
…same file (#38213)

Prior to this commit, duplicated styles defined in multiple components in the same file were not
shared between components, thus causing extra payload size. This commit updates compiler logic to
use `ConstantPool` for the styles (while generating the `styles` array on component def), which
enables styles sharing when needed (when duplicates styles are present).

Resolves #38204.

PR Close #38213
Splaktar added a commit to angular-hispano/angular that referenced this issue Aug 8, 2020
…same file (angular#38213)

Prior to this commit, duplicated styles defined in multiple components in the same file were not
shared between components, thus causing extra payload size. This commit updates compiler logic to
use `ConstantPool` for the styles (while generating the `styles` array on component def), which
enables styles sharing when needed (when duplicates styles are present).

Resolves angular#38204.

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

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Aug 27, 2020

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 Aug 27, 2020
profanis added a commit to profanis/angular that referenced this issue Sep 5, 2020
…same file (angular#38213)

Prior to this commit, duplicated styles defined in multiple components in the same file were not
shared between components, thus causing extra payload size. This commit updates compiler logic to
use `ConstantPool` for the styles (while generating the `styles` array on component def), which
enables styles sharing when needed (when duplicates styles are present).

Resolves angular#38204.

PR Close angular#38213
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants