Welcome to gatsby@4.1.0 release (November 2021 #1)

Key highlights of this release:

Also check out notable bugfixes.

Bleeding Edge: Want to try new features as soon as possible? Install gatsby@next and let us know if you have any issues.

Previous release notes

Full changelog


Support for Deferred Static Generation in File System Route API

With the introduction of Deferred Static Generation (DSG) (What is DSG?) you can defer non-critical page generation to the first user request. Currently, you can only achieve this by setting defer: true in the createPage action.

You’re now also able to use DSG with File System Route API. For this we’re introducing a new API inside File System Route templates that we’ll continue to improve: A config() function. You’ll be able to use it like this:

In the async function config() you can use GraphQL to query the data layer you’re used to. But you don’t have to — you can also use regular JavaScript or skip the outer function completely. config() must return a function itself in which you get params as an argument. params is the same object you also get as props.params in the page component (see params documentation), e.g. src/pages/{Product.name}.js has params.name.

Here’s a minimal version of config() that defers every page of the current File System Route template:

You can read the API reference or the DSG guide to learn more.

Please note: As DSG has no effect in gatsby develop at the moment you can only test config() in gatsby build right now. As this is the first iteration of the config() API we’re looking for feedback!

JSX Runtime Options in gatsby-config.js

You now can configure the jsxRuntime and jsxImportSource inside gatsby-config.js:

Setting jsxRuntime to automatic allows the use of JSX without having to import React (learn more in the official blog post). You can use the jsxImportSource option to set which package React should use as underlying JSX transformer.

Notable bugfixes & improvements

  • We’ve improved our Creating a Source Plugin guide to account for changes made in v4
  • gatsby-source-contentful: The downloadLocal option is working correctly again, via PR #33715
  • gatsby-plugin-image:
    • Remove flickering and blinking on re-renders, via PR #33732
    • Fix GatsbyImage not displaying image in IE11, via PR #33416
  • gatsby:
    • Cache Query Engine & SSR engine (when you use DSG) to improve build times, via PR #33665
    • Pass pageContext to getServerData(), via PR #33626
  • gatsby-remark-images: Fix figure caption generation when using GATSBY_EMPTY_ALT, via PR #30468
  • gatsby-plugin-sharp: Pass failOnError to sharp when using gatsby-plugin-image, via PR #33547

Contributors

A big Thank You to our community who contributed to this release 💜