Skip to content

Commit

Permalink
perf: set FontAwesome icons size always static
Browse files Browse the repository at this point in the history
so they're shown when using SSR as early as possible
remove from NoJS only and use always to improve SSR shifts too
explain it
  • Loading branch information
davidlj95 committed Sep 29, 2023
1 parent d3212fd commit 0b3596e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@
top: 100px;
min-height: calc(100% - 100px) !important;
}

fa-icon > svg {
/* Otherwise, doesn't display when JavaScript is disabled */
height: 100%;
}
</style>
</noscript>
</head>
Expand Down
12 changes: 12 additions & 0 deletions src/sass/_font-awesome.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// When JavaScript is disabled and page is pre-rendered with SSR Font Awesome icons seemed to be there in the DOM,
// but without their size set.
//
// Seems size is set dynamically by Font Awesome library. With this trick, we make icons always appear by setting its
// size. Which also helps with SSR, given there are less layout shifts. As it appears there from early beginning, not
// until its size is dynamically set
@mixin iconsStaticSizeFix {
fa-icon > svg {
/* Otherwise, doesn't display when JavaScript is disabled */
height: 100%;
}
}
4 changes: 4 additions & 0 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@use 'app/header/header-theme';
@use 'app/no-script/no-script-theme';
@use 'app/navigation-tabs/navigation-tabs-theme';
@use 'font-awesome';
@use 'theming';
@use 'typographies';

Expand Down Expand Up @@ -81,3 +82,6 @@ html:not([data-no-motion]) {
@include about-theme.motion;
@include navigation-tabs-theme.motion;
}

// Font Awesome quirk
@include font-awesome.iconsStaticSizeFix;

0 comments on commit 0b3596e

Please sign in to comment.