Add support for per-component stylesheets#8375
Conversation
There was a problem hiding this comment.
I'd like to find a better way to do this, since having some files with @use 'uswds-core' as *; and others with @use 'required' as *; is going to cause confusion, but Sass compilation will error when trying to load both uswds-core and required as separate directives.
There was a problem hiding this comment.
b8b4f67 is a slight improvement at least as far as restoring @use 'uswds-core' as *; as the conventional way to bring USWDS functions in scope.
It might be more streamlined to go the opposite direction, creating a separate "core" entrypoint that we maintain (basically what required is), and change every stylesheet to use that instead. Then, we still have consistency, while only needing one @use 'core' as *;, vs. separate @forward 'required'; @use 'uswds-core' as *;. The downside is this moves away from how someone might expect to use USWDS. It could be interesting to try to add another layer of "interception" like what LGDS does, so that @use 'uswds-core' as *; is actually loading a stylesheet internal to the IdP.
There was a problem hiding this comment.
It could be interesting to try to add another layer of "interception" like what LGDS does, so that
@use 'uswds-core' as *;is actually loading a stylesheet internal to the IdP.
Gave this a try in 316cfd431. The hard part was figuring out how to load the "original" uswds-core, but I managed it by adding node_modules as a separate load path and referencing the @18f/identity-design-system path from there.
This might create some possible performance impact depending if more load paths causes a lot of filesystem noise, since we only need to resolve node_modules in this one location, but now it'll be the first thing checked for every @forward, @use, and @import.
There was a problem hiding this comment.
This might create some possible performance impact depending if more load paths causes a lot of filesystem noise, since we only need to resolve
node_modulesin this one location, but now it'll be the first thing checked for every@forward,@use, and@import.
Apparently I forgot that node_modules is a load path by default 😅
|
Do we have a component in mind we wanted to demo this with? |
The changes are already updating Some other good candidates:
Ones which would be good to do, but blocked by React usage:
I think this would also give us a pattern to create new component semantics around what are currently implemented as ad-hoc CSS classes, e.g.:
|
|
It might be worth considering if there's more harm than good by splitting out e.g. 3 lines of styles to a separate CSS file, but I'm inclined to say "yes" all things considered, as long as the overhead to implement is minimal (it's actually less work in this proposed approach than in the status quo). |
ah whoops yes! the diff to that stylesheet was so small, I didn't register it was a move, makes sense! 👍 |
2 similar comments
ah whoops yes! the diff to that stylesheet was so small, I didn't register it was a move, makes sense! 👍 |
ah whoops yes! the diff to that stylesheet was so small, I didn't register it was a move, makes sense! 👍 |
cb360e9 to
4032301
Compare
changelog: Internal, Optimization, Reduce size of stylesheet assets for critical path
4032301 to
dfe4e0e
Compare
* Add support for per-component stylesheets changelog: Internal, Optimization, Reduce size of stylesheet assets for critical path * Forward required to use uswds-core conventionally * Override _uswds-core via internal load path * Remove unnecessary load path * Prioritize `--load-path` flag in Sass load path resolution * Add specs for component stylesheets * Add specs for StylesheetHelper * Rename clipboard component stylesheet to simple scss * Render stylesheet_once_tags everywhere application is rendered * Fix component preview for per-component stylesheet
* LG-8349: Move AddressSearch component into own package changelog: Internal, Code Structure, separate AddressSearch UI component as package. * LG-8439: remove old component. * LG-8439: package information. * LG-8439: change log file. * LG-8439: address comments * Update app/javascript/packages/address-search/README.md Co-authored-by: Tim Bradley <90272033+NavaTim@users.noreply.github.com> * Update app/javascript/packages/address-search/index-spec.tsx Co-authored-by: Tim Bradley <90272033+NavaTim@users.noreply.github.com> * LG-8439: extra / not needed. * Add support for per-component stylesheets (#8375) * Add support for per-component stylesheets changelog: Internal, Optimization, Reduce size of stylesheet assets for critical path * Forward required to use uswds-core conventionally * Override _uswds-core via internal load path * Remove unnecessary load path * Prioritize `--load-path` flag in Sass load path resolution * Add specs for component stylesheets * Add specs for StylesheetHelper * Rename clipboard component stylesheet to simple scss * Render stylesheet_once_tags everywhere application is rendered * Fix component preview for per-component stylesheet * LG-8439: resolve conflict * LG-8439: address comments * Updating how gpo pending is set in dummy profile (#8434) * Updating how gpo pending is set in dummy profile * changelog [skip changelog] --------- Co-authored-by: Tim Bradley <90272033+NavaTim@users.noreply.github.com> Co-authored-by: Andrew Duthie <andrew.duthie@gsa.gov> Co-authored-by: Eric Gade <105373963+eric-gade@users.noreply.github.com>
🛠 Summary of changes
Supports components implementing stylesheet "sidecar" assets, with a similar developer experience to how it functions for JavaScript/TypeScript files.
This is a continuation of the idea originally proposed in #6168, which is now more supportable with USWDS v3's new component-specific imports.
Why?
Results:
This is a minimal proof-of-concept, so the impact is not expected to be drastic.
Before: 29.8kb
After: 29.6kb
📜 Testing Plan
Repeat Testing Plan from #8307. There should be no visual impact of these changes.