question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[gatsby-plugin-preload-fonts] Add option to skip checking if fonts change - to use in CI

See original GitHub issue

Summary

gatsby-plugin-preload-fonts requires user action if fonts are detected to be unchanged. This makes it impossible to use with any CI tool as it will hang the build. It would be useful to have an option to provide a flag/env variable that would skip this check or force it to be done again.

Basic example

Currently for each page hash is created a

const {GATSBY_PLUGIN_PRELOAD_FONTS_FORCE} = process.env

const shouldForceCrawl = GATSBY_PLUGIN_PRELOAD_FONTS_FORCE

const hash = crypto.createHash(`md5`)
  routes.forEach(r => hash.update(r))
  if (cache.hash === hash.digest(`hex`)) {
    const lastRun = formatRelative(new Date(cache.timestamp), new Date())
    const ok = shouldForceCrawl ? true : await logger.confirm(`

  ${blue(`note`)} routes have not changed from the last run; if you haven't
       added any new routes or font requirements since then, you
       should be good to go! would you like to crawl them anyways?

         - ${dim(`last run`)} ${bold(lastRun)}
         - ${dim(`route hash`)} ${bold(cache.hash)}

`)
    if (!ok) process.exit(0)
  }

If the proposal involves a new or changed API, include a basic code example. Omit this section if it’s not applicable.

Motivation

To enable using this plugin in CI

I can provide PR

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
superhawk610commented, Jan 14, 2020

Hey everyone, sorry for the delay in chiming in. Let me explain a bit about my reasoning for keeping this outside of CI, hopefully that will provide some clarity.

There are 3 situations where you need to run gatsby-preload-fonts to regenerate the font cache:

  • after you have manually added new routes (usually by adding a new file in the pages directory)
  • after you’ve added a new plugin that generates new routes (e.g. source plugins, etc)
  • after you’ve added new fonts that require preloading to existing routes

Gatsby can automatically detect new routes (the first situation), which is what we use to check/update the cache hash. However, the 2nd and 3rd situation are too high-level to be automatically detected and thus must be manually enforced by the developer.

Detecting fonts that need to be preloaded can become quite time consuming for any project larger than a few routes, often taking 10-15 minutes or more (it has to crawl every route in your site, dynamic and static). As such, I believe rerunning this script on every CI build will very often simply waste resources without any actual benefit.

That being said, I do think rerunning this script anytime the cache hash changes (whenever new routes can be detected by Gatsby) would be useful and wouldn’t needlessly waste resources. @masives if you’d like to open a PR to add a non-interactive mode for gatsby-preload-fonts in CI environments whenever the cache hash has changed, I believe that would be a useful addition.

@pieh does that help clear things up?

0reactions
github-actions[bot]commented, Mar 1, 2020

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community! 💪💜

Read more comments on GitHub >

github_iconTop Results From Across the Web

gatsby-plugin-preload-fonts - npm
Start using gatsby-plugin-preload-fonts in your project by running ... if your application routes don't change but you add new font assets).
Read more >
Set IM options in Skype for Business - Microsoft Support
The IM options window in Skype for Business is where you can apply settings for spell-checking, changing fonts, and showing emoticons in your...
Read more >
Fonts - Shopify.dev
The following outlines how to use fonts from the Shopify font library in your theme: Add a font_picker type setting to allow merchants...
Read more >
Change Font Book settings on Mac - Apple Support
Use Font Book settings to change options for where fonts are installed and how duplicates are handled. To change these settings in the...
Read more >
Extremely fast loading with Gatsby and self-hosted fonts
You can switch branches to test the different solutions for yourself. Setting up a new Gatsby project. We'll use the gatsby-cli to create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found