-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Reimplement gridicons using SVG external content. #32763
Conversation
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Webpack Runtime (~360 bytes removed 📉)
Webpack runtime for loading modules. It is included in the HTML page as an inline script. Is downloaded and parsed every time the app is loaded. App Entrypoints (~44696 bytes removed 📉)
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Legacy SCSS Stylesheet (~157 bytes added 📈)
The monolithic CSS stylesheet that is downloaded on every app load. Sections (~20237 bytes removed 📉)
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~118369 bytes removed 📉)
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Gridicons (~228362 bytes removed 📉)
Set of SVG icons that is loaded asynchronously to not delay the initial load. Unless you are modifying Gridicons, you should not see any change here. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
c5e2203
to
1ccb040
Compare
b677ab1
to
21625f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a little glitch with needs-offset
and IE11.
I also have one question: when using the use xlink:href
reference, can we target elements inside the SVG with CSS? I think we might use it at a few places, I'm not sure.
assets/stylesheets/_vendor.scss
Outdated
@@ -5,15 +5,15 @@ | |||
.gridicon { | |||
fill: currentColor; | |||
|
|||
&.needs-offset g { | |||
&.needs-offset use { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the svg4everybody
polyfill is active, there won't be any use
elements to style. The polyfill will remove them and replace with the SVG markup it downloads with XHR.
We need a style that targets both g
and use
elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent catch, thanks @jsnajdr !
I have pushed a fix for this using :first-child
. Waiting for calypso.live
before testing on IE11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix appears to be working, from what I can tell.
We can't, no; it's effectively a shadow DOM. I couldn't find any instances of this targeting other than for alignment, which I rewrote in CSS. |
Yes, I also found only instances where we style the top-level |
This ensures that alignment works both in polyfilled and non-polyfilled setups.
assets/stylesheets/_vendor.scss
Outdated
@@ -5,15 +5,15 @@ | |||
.gridicon { | |||
fill: currentColor; | |||
|
|||
&.needs-offset g { | |||
&.needs-offset :first-child { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the whole SVG is inline rather than referenced, doesn't this also offset all nested elements that happen to be the first child of their parent?
&.needs-offset > g:first-child, &.needs-offset > use:first-child {
transform: ...
}
should be more reliable. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, once again! But if the concern is to restrict to immediate descendants, then the following should suffice:
&.needs-offset > :first-child {
transform: ...
}
Would you prefer for me to still explicitly mention g
and use
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you prefer for me to still explicitly mention g and use?
Not really needed, just more safe and explicit IMO 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, I'l switch to that, then :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 🎉
When Gridicons were redone in #32763, they switched from being Class components to Functional components. Functional components cannot be the target of a React ref unless the ref is forwarded using React.createRef. We use Gridicons by ref a number of places in Calypso as popover contexts. Add ref forwarding to fix various places.
When Gridicons were redone in #32763, they switched from being Class components to Functional components. Functional components cannot be the target of a React ref unless the ref is forwarded using React.createRef. We use Gridicons by ref a number of places in Calypso as popover contexts. Add ref forwarding to fix various places.
Per prop change in #32763 - Change CartSummaryBar GridIcon size to numeric
Reimplement gridicons using an SVG external content approach, instead of SVG transpiled into React components. This helps keep images as images (which is good for performance), while maintaining styleability. Old browsers are supported through the already-included svg4everyone polyfill.
This PR supersedes and replaces #32172.
See #32364 for a similar change, which added Material Icons with the same approach.
Changes proposed in this Pull Request
gridicons
NPM package.Testing instructions