Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
Add condition to default mixins to ensure they're only run once (#240)
Browse files Browse the repository at this point in the history
As this component is likely to be included by many other components the nested loops inside
of these mixins can have a drastic effect on project build performance.

For example the Sass build step for the FT.com search page app can currently take over 40
seconds but only 1-3 seconds after.
  • Loading branch information
i-like-robots authored and notlee committed Dec 30, 2019
1 parent 7b21518 commit 56463a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 10 additions & 4 deletions main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
@import 'src/scss/mixins';

// Set the palette colors programatically
@include _oColorsSetDefaultPaletteColors();
@include _oColorsSetPaletteMixes();
@include _oColorsSetPaletteTones();
@include _oColorsSetDefaultUsecases();
// NOTE: Only do this once as this partial will be included by many other components
// and the multiple nested loops can have a huge effect on compilation performance.
@if ($_o-colors-is-initialised == false) {
@include _oColorsSetDefaultPaletteColors();
@include _oColorsSetPaletteMixes();
@include _oColorsSetPaletteTones();
@include _oColorsSetDefaultUsecases();

$_o-colors-is-initialised: true !global;
}

/// Output `o-colors` CSS.
///
Expand Down
5 changes: 5 additions & 0 deletions src/scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
/// @access public
$o-colors-is-silent: true !default;

/// Ensure default mixins are only called once
/// @type Bool
/// @access private
$_o-colors-is-initialised: false !default;

/// A map to define default palette colours:
/// A list of arguments for `oColorsSetColor`, except the project name.
///
Expand Down

0 comments on commit 56463a5

Please sign in to comment.