Problem/Motivation
Originally from
From #3079738-49: Add Claro administration theme to core:
+++ b/core/themes/claro/css/dist/components/action-link.css @@ -0,0 +1,276 @@ + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14px' height='16px' viewBox='0 0 14 16'%3E%3Cpath fill='%23545560' d='M13.9,2.9c-0.1-0.4-0.2-0.6-0.2-0.6c-0.1-0.4-0.4-0.4-0.8-0.5l-2.3-0.3c-0.3,0-0.3,0-0.4-0.3 C9.8,0.5,9.7,0,9.3,0H4.7C4.3,0,4.2,0.5,3.8,1.3C3.7,1.5,3.7,1.5,3.4,1.6L1.1,1.9C0.7,1.9,0.4,2,0.3,2.3c0,0-0.1,0.2-0.2,0.5 C0,3.4-0.1,3.3,0.4,3.3h13.2C14.1,3.3,14,3.4,13.9,2.9z M12.4,4.7H1.6c-0.7,0-0.8,0.1-0.7,0.6l0.8,10.1C1.8,15.9,1.8,16,2.5,16h9.1 c0.6,0,0.7-0.1,0.8-0.6l0.8-10.1C13.2,4.8,13.1,4.7,12.4,4.7z'/%3E%3C/svg%3E");🤓 Have these SVGs been optimized?
🤔🤔🤔 More importantly: why are these inlined already? (These were done in #3036732: Action link component.) I'm sure that the build tools (#3060153: Use PostCSS in core, initially only for Claro) allow this to happen at build time? That'd make it much easier to inspect the SVGs, to apply SVG optimization tools, to encourage reuse, etc. It also allows us to decide whether we truly want to inline these as
data:URIs, or whether it makes more sense to let them be loaded by HTTP requests. This particular CSS file is 24 KB ungzipped and unminified. That's … a lot. Most of that is due to these inlined SVG files (this CSS file is the single largest CSS file in Claro).In other words: for developer ergonomics and for web performance optimization reasons I think we should consider changing this.
In #3083657: Devise strategy to address several SVG loading+usage issues, it was agreed this was a sound approach.
Proposed resolution
Evaluate a build tools that will inline the SVGs from the .pcss.css files when compiled to their .css counterparts.
For each inlined svg either:
- Un-inline
- Or document why it's inlined
For all of them, regardless of the above choice: optimize them. Using for example https://imageoptim.com.
Remaining tasks
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #39 | interdiff.txt | 514 bytes | lauriii |
| #39 | 3085245-39.patch | 238.32 KB | lauriii |
| #36 | 3085245-36.patch | 237.82 KB | effulgentsia |
| #32 | 3085245-32.patch | 238.88 KB | bnjmnm |
| #32 | interdiff_28-32.txt | 171.86 KB | bnjmnm |
Comments
Comment #2
wim leersComment #3
lauriiiComment #4
huzookaComment #5
martijn.cuppens commentedI think we better insert the svg icons for the action links in the html. This way we'll need a lot less images since we can set the color with css (see https://css-tricks.com/change-color-of-svg-on-hover/#article-header-id-0)
Comment #6
bnjmnmComment #7
bnjmnmComment #8
bnjmnmThis patch uses postcss-url Nothing inlined has been un-inlined yet. Just providing this here for evaluation. Not entirely sure if other alternatives exist but I'll do some investigating before I jump into a dependency evaluation on this one.
Comment #9
bnjmnmThe other plugin option would be https://www.npmjs.com/package/postcss-inline-svg, this also inlines SVGs, with pretty distinct pros and cons against postcss-url:
CON: inlining requires additional non-CSS syntax. The SVG Urls need to be wrapped in a plugin-provided function.
svg-load('img/arrow-up.svg'), while postcss-url acts on standard CSS syntaxPRO: it is possible to add args that make it possible to control attributes with that function
svg-load('img/arrow-up.svg', fill=#000, stroke=#fff), so that could reduce the total amount of SVG files needed (although of course it would not reduce the size of the compiled CSS files).Comment #10
lauriiiFor now, postcss-url seems fine. Since it's using standard CSS syntax, it should be easy for us to convert to svg-load if we deem that useful in the future.
Comment #11
bnjmnmDependency Evaluation
The majority of the dependencies required by postcss-url are already part of Drupal core. These are the dependencies added:
Note that I mention weekly NPM download numbers as a fuzzy gauge of how widely used these packages are. This is obviously a fuzzy figure since a single project can have hundreds of builds per week, each one pulling in the library again, but it can help distinguish wide use vs limited.
postcss-url (PostCSS plugin)
cuint
mime
xxhashjs
Comment #12
bnjmnmThis un-inlines all inlined CSS in Claro. The SVGs were also manually optimized with svgo. This optimization could eventually be added to the build process, via something like cssnano , but that doesn't need to weigh down this issue and its already sizeable patch. No interdiff as this is substantially different from the prior patch
Also attached is output from wraith regressions testing, which has found no difference between HEAD and the changes here. Wraith was supplemented with manual testing since it can't account for states like hover and active.
Comment #13
nod_Potentially addressing this one (in claro at least)?
Comment #14
lauriiiComment #15
narendra.rajwar27Comment #16
narendra.rajwar27Patch re-rolled for 9.1.x as comment #14.
Comment #17
bnjmnmThanks for #16, this is not fully rerolled unfortunately. The purpose of this issue is to refactor all inline SVGs in pcss.css files, and one was added in dialog.pcss.css since patch #12
This needs to reference a file instead of
data:image/svg+xml,. If an SVG of this image is not yet in core it will need to be added.Comment #18
narendra.rajwar27@bnjmnm, thank you for reviewing. here are some points:
1- As you said
, I could not find that file in patch #12.
2- This one
, how to find a file reference or to add svg file if not present.
Please share your feedback.
Thanks again.
Comment #19
bnjmnmThat's because It's not in the patch :) The purpose of this issue is to un-inline all SVGs. Since the creation of patch #12, a new inlined svg was added to the Claro theme in dialog.pcss.css, as seen in the snippet in #17 This inlined SVG needs to be addressed in the same manner as the other ones in this patch.
- Create a new empty .svg file in the folder that matches its hex color.
- Decode the CSS inlined SVG with a utility like https://mothereff.in/url
- Paste the decoded SVG markup into the SVG file you created
- Change
background: url("data:image/svg+xml,...:to reference the file you just created, instead of the inlined SVG.- When in doubt, there are over 80 examples of this process in patch #12, referencing those may help clear up any confusion.
Comment #20
narendra.rajwar27Comment #21
narendra.rajwar27Updated the patch for the file
dialog.pcss.css, Please review.Comment #22
lauriiiI think the patch in #21 is missing some of the icons.
I'm wondering if we actually want to ship the icons in the
core/miscfolder or if they should be in the Claro theme directory. I know that historically we have shipped icons there, but I'm wondering if it's a pattern we want to continue. I feel conflicted because it isn't necessarily something we would have to decide as part of this issue, but on the other hand it would be more difficult to make the change after we've added these icons in thecore/miscfolder because we would have to ensure that none of the images are being referenced elsewhere.Comment #23
bnjmnm@lauriii is correct, the patch appears to be missing icons. As it's not clear what was undone in #21, this is diffed from #12.
Re #22, I'm partial to continuing the pattern of using core/misc for icons to encourage reuse in contrib. Their location signifies it's available for use with anything that extends core as opposed to a specific theme. This helps facilitate a more consistent UI, and makes it easier for contributors to leverage existing resources instead of manifesting new ones. The point about it being difficult to revert such a change is noted, I'm trying to think of scenarios where this may be wanted - the one that comes to mind is it would be possible remove these images when Claro is removed sometime between Drupal 11 and 99. There may be additional reasons that haven't occurred to me.
Comment #24
lauriiiSome of the icons in
core/miscare being used by contrib but the usage is very limited because contrib cannot properly access the icons in CSS because it's not possible for them to know in which folder the module or theme will be installed. For the icons to be reusable, we probably need something like #1849712: Add theming template and prepare logic for rendering icons first. Main reason for not adding the icons to core/misc is that it will be make it harder to discover icons used by Claro. Also, one of the reasons for the icons to exist in the core/misc is core reusability. This would mostly mean modules which I believe goes against our decision of not having designs in modules.Comment #25
bnjmnmGood point in #24, with uncertain paths there's not much use in offering the icons to all of core. The icons created in this patch have been moved to Claro.
Comment #26
katherinedBased on the thorough evaluation in #11, postcss-url seems like a great solution, both for its maintainership and use of standard syntax as @lauriii mentioned previously. Since core is already using PostCSS, adding this plugin should make for an efficient workflow.
#24 is also a logical approach, in my opinion.
Comment #27
lauriiiI tested most of the changes manually by using cd_tools. On top of that, I tested manually breadcrumbs and off-canvas title icon. I also tested media library and status report even though their source CSS wasn't changed as part of the patch, just to make sure that pre-existing references to icons work correctly.
Seems like there's now 9.0.0. I think we should upgrade to that before committing this
Why do we need to add !important here?
Comment #28
bnjmnm#27.1
. 9.0 is currently a beta that hasn't budged for 16 months. Is there an interest in vetting and adding this anyway to avoid the upgrade hassle later?
#27.2
We don't, looks like it was added by accident during the refactoring - fixed every instance in the file
#27.3
Added a CR and updated the documentation here: https://www.drupal.org/docs/core-modules-and-themes/core-themes/claro-th...
Comment #29
lauriiiAwesome. I didn't notice the postcss-url 9.0.0 was in beta when I checked their latest version. I think we can update to that once they have a supported release. I think this is ready 👍
Comment #30
olli commentedWhy not decode special characters with the optimizeSvgEncode option?
Are *.gif and *.png files inlined here on purpose or should we use a filter to inline only *.svg?
Comment #31
lauriiiGood points! We should probably set a filter to leave *.gif and *.png files out.
Comment #32
bnjmnmGreat feedback in #30. This should address both points.
Comment #33
lauriii#32 addresses feedback from #30
Comment #35
bnjmnmTest failure that kicked this back to "Needs Work" was an unrelated CKEditor test known to intermittently fail and is not at all touched by the changes in this patch. Switching back to RTBC.
Comment #36
effulgentsia commentedThis removes the hunk from form.css that was made obsolete by #3127466: Required fields are not identifiable on Internet Explorer 11 high contrast.
Comment #37
effulgentsia commentedAdding reviewer credits.
Comment #38
effulgentsia commentedSome of the files in this patch don't pass the spell checking that runs in our pre-commit hook:
From the core directory:
Should we add these to
misc/cspell/dictionary.txtor do something else?Comment #39
lauriiiAdded those terms to
core/misc/cspell/dictionary.txtand tested that the spellcheck on these files pass now.Comment #41
effulgentsia commentedThanks! Pushed to 9.1.x. I agree with the reasoning in #11 that the new JS dependencies are reasonable to add, considering that they're only dev dependencies.
Comment #43
quietone commentedpublish change record