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

fix(material/schematics): Create a schematic to add the base theme dimension #27964

Merged
merged 1 commit into from
Oct 20, 2023

Conversation

mmalerba
Copy link
Contributor

As of v17, users need to include the new "base" theme dimension for the components they use. For users that are using the "theme" mixins now, the base dimension will be pulled in automatically. However, for users using the "color", "typography", and "density" mixins only, they will need to include the "base" mixin as well.

This schematic works by scanning all of the app's Sass to determine which components had their "color", "typography", or "density" mixins included, but did not have their "theme" mixin included. It then locates all of the calls to "mat.core()" and inserts calls to the "base" mixins for the identified compoennts, immediately following. It makes sense to use "mat.core()" as a signal for when to insert them, because the "base" mixins should be used once-per-app, like "mat.core()". We can't guarantee that a "$theme" will be available at the insertion point, so we create a "$dummy-theme" to pass to the base mixins.

We also insert a comment above the new mixins explaining why they were added and a TODO to clean up the "$dummy-theme". Once we have the documentation updated to cover the base dimension, we should follow-up by linking to it from the inserted comment.

@mmalerba mmalerba added the target: rc This PR is targeted for the next release-candidate label Oct 19, 2023
@mmalerba mmalerba added this to the 17.0.0 milestone Oct 19, 2023
Copy link
Contributor

@andrewseguin andrewseguin left a comment

Choose a reason for hiding this comment

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

All looks good to me - thanks for making the functions clear to understand. It seems there's a fair amount of utility functions that could be useful to other migrations in the future - would be nice if they were in a shared folder or otherwise we should remember to refactor that another time.

One question - would it be better to not define dummy-theme so that it causes a compilation error? I'm worried users will not realize we added this and it'l silently work.

@mmalerba mmalerba force-pushed the base-schematic branch 2 times, most recently from f9ccef0 to 4bbf77c Compare October 19, 2023 21:44
…mension

As of v17, users need to include the new "base" theme dimension for the
components they use. For users that are using the "theme" mixins now,
the base dimension will be pulled in automatically. However, for users
using the "color", "typography", and "density" mixins only, they will
need to include the "base" mixin as well.

This schematic works by scanning all of the app's Sass to determine
which components had their "color", "typography", or "density" mixins
included, but did *not* have their "theme" mixin included. It then
locates all of the calls to "mat.core()" and inserts calls to the "base"
mixins for the identified compoennts, immediately following. It makes
sense to use "mat.core()" as a signal for when to insert them, because
the "base" mixins should be used once-per-app, like "mat.core()". We
can't guarantee that a "$theme" will be available at the insertion
point, so we create a "$dummy-theme" to pass to the base mixins.

We also insert a comment above the new mixins explaining why they were
added and a TODO to clean up the "$dummy-theme". Once we have the
documentation updated to cover the base dimension, we should follow-up
by linking to it from the inserted comment.
@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Oct 20, 2023
@mmalerba mmalerba removed the request for review from devversion October 20, 2023 20:34
@mmalerba mmalerba merged commit c92fdad into angular:main Oct 20, 2023
23 of 25 checks passed
mmalerba added a commit that referenced this pull request Oct 20, 2023
…mension (#27964)

As of v17, users need to include the new "base" theme dimension for the
components they use. For users that are using the "theme" mixins now,
the base dimension will be pulled in automatically. However, for users
using the "color", "typography", and "density" mixins only, they will
need to include the "base" mixin as well.

This schematic works by scanning all of the app's Sass to determine
which components had their "color", "typography", or "density" mixins
included, but did *not* have their "theme" mixin included. It then
locates all of the calls to "mat.core()" and inserts calls to the "base"
mixins for the identified compoennts, immediately following. It makes
sense to use "mat.core()" as a signal for when to insert them, because
the "base" mixins should be used once-per-app, like "mat.core()". We
can't guarantee that a "$theme" will be available at the insertion
point, so we create a "$dummy-theme" to pass to the base mixins.

We also insert a comment above the new mixins explaining why they were
added and a TODO to clean up the "$dummy-theme". Once we have the
documentation updated to cover the base dimension, we should follow-up
by linking to it from the inserted comment.

(cherry picked from commit c92fdad)
@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 Nov 20, 2023
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 target: rc This PR is targeted for the next release-candidate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants