|
| 1 | +--- |
| 2 | +date: "2022-02-22" |
| 3 | +version: "4.8.0" |
| 4 | +title: "v4.8 Release Notes" |
| 5 | +--- |
| 6 | + |
| 7 | +Welcome to `[email protected]` release (February 2022 #2) |
| 8 | + |
| 9 | +Key highlights of this release: |
| 10 | + |
| 11 | +- [Support for TypeScript in `gatsby-browser` and `gatsby-ssr`](#support-for-typescript-in-gatsby-browser-and-gatsby-ssr) |
| 12 | +- [New TypeScript option when creating Gatsby projects from the CLI](#new-typescript-option-when-creating-gatsby-projects-from-the-cli) |
| 13 | +- [Significant memory usage reduction when filtering and sorting nodes](#significant-memory-usage-reduction-when-filtering-and-sorting-nodes) |
| 14 | +- [New APIs in `gatsby-core-utils` and `gatsby-plugin-utils`](#new-apis-in-gatsby-core-utils-and-gatsby-plugin-utils) |
| 15 | + |
| 16 | +Also check out [notable bugfixes](#notable-bugfixes--improvements). |
| 17 | + |
| 18 | +**Bleeding Edge:** Want to try new features as soon as possible? Install `gatsby@next` and let us know |
| 19 | +if you have any [issues](https://github.com/gatsbyjs/gatsby/issues). |
| 20 | + |
| 21 | +[Previous release notes](/docs/reference/release-notes/v4.7) |
| 22 | + |
| 23 | +[Full changelog][full-changelog] |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Support for TypeScript in `gatsby-browser` and `gatsby-ssr` |
| 28 | + |
| 29 | +In addition to Gatsby's [current TypeScript support for your site's `.ts`/`.tsx` files](/docs/how-to/custom-configuration/typescript/#introduction), you can now [use TypeScript with your `gatsby-browser` and `gatsby-ssr` files](/docs/how-to/custom-configuration/typescript/#gatsby-browsertsx--gatsby-ssrtsx). |
| 30 | + |
| 31 | +The `GatsbyBrowser` and `GatsbySSR` types can now be used in `gatsby-browser.tsx` and `gatsby-ssr.tsx` respectively. |
| 32 | + |
| 33 | +```tsx:title=gatsby-browser.tsx |
| 34 | +import * as React from "react" |
| 35 | +import { GatsbyBrowser } from "gatsby" |
| 36 | + |
| 37 | +export const wrapPageElement: GatsbyBrowser["wrapPageElement"] = ({ element }) => { |
| 38 | + return ( |
| 39 | + <div> |
| 40 | + <h1>Hello World</h1> |
| 41 | + {element} |
| 42 | + </div> |
| 43 | + ) |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +```tsx:title=gatsby-ssr.tsx |
| 48 | +import * as React from "react" |
| 49 | +import { GatsbySSR } from "gatsby" |
| 50 | + |
| 51 | +export const wrapPageElement: GatsbySSR["wrapPageElement"] = ({ element }) => { |
| 52 | + return ( |
| 53 | + <div> |
| 54 | + <h1>Hello World</h1> |
| 55 | + {element} |
| 56 | + </div> |
| 57 | + ) |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +Work is in progress for TypeScript support for `gatsby-config` and `gatsby-node` files. Check out the [RFC](https://github.com/gatsbyjs/gatsby/discussions/34613) to learn how to test it out today. |
| 62 | + |
| 63 | +## New TypeScript option when creating Gatsby projects from the CLI |
| 64 | + |
| 65 | +When [initializing new Gatsby projects](/docs/quick-start/) with `gatsby new`, `npm init gatsby`, or `npx create-gatsby`, you can now select JavaScript or TypeScript as an option to start your project with. |
| 66 | + |
| 67 | +After calling one of the above commands with no flags, the third question will now be: "Will you be using JavaScript or TypeScript?". Selecting JavaScript will start your project with [`gatsby-starter-minimal`](https://github.com/gatsbyjs/gatsby/tree/master/starters/gatsby-starter-minimal), and selecting TypeScript will start your project with [`gatsby-starter-minimal-ts`](https://github.com/gatsbyjs/gatsby/tree/master/starters/gatsby-starter-minimal-ts). |
| 68 | + |
| 69 | +A [new `-ts` flag](/docs/quick-start/#use-flags) has been added for use with `npm init gatsby` and `npx create-gatsby`. Executing `npm init gatsby -ts` or `npx create-gatsby -ts` will skip the language question and start your project with [`gatsby-starter-minimal-ts`](https://github.com/gatsbyjs/gatsby/tree/master/starters/gatsby-starter-minimal-ts). |
| 70 | + |
| 71 | +Lastly, arguments for Gatsby initializer commands are now _not positional_. Any order of your desired site name and flags will work as expected (e.g. `npm init gatsby -ts hello-world -y`). |
| 72 | + |
| 73 | +## Significant memory usage reduction when filtering and sorting nodes |
| 74 | + |
| 75 | +Gatsby no longer stores whole nodes in memory when executing filtering and sorting processes on your site. Now, Gatsby uses weak references and node partials, resulting in significant memory usage reduction for sites with many large nodes. |
| 76 | + |
| 77 | +See [PR #34747](https://github.com/gatsbyjs/gatsby/pull/34747) for more information. |
| 78 | + |
| 79 | +## New APIs in `gatsby-core-utils` and `gatsby-plugin-utils` |
| 80 | + |
| 81 | +Two new APIs have been added: |
| 82 | + |
| 83 | +- `createMutex` in `gatsby-core-utils`, via [PR #34761](https://github.com/gatsbyjs/gatsby/pull/34761) |
| 84 | +- `hasFeature` in `gatsby-plugin-utils`, via [PR #34748](https://github.com/gatsbyjs/gatsby/pull/34748) |
| 85 | + |
| 86 | +Calling `createMutex` gives you a [mutex](https://en.wikipedia.org/wiki/Mutual_exclusion) that you can use to safely perform processes concurrently in places where that matters, such as in workers. |
| 87 | + |
| 88 | +For example in the code below, one worker can execute while all others wait for it to finish. This is handy in scenarios like writing to the same file to disk. |
| 89 | + |
| 90 | +```js |
| 91 | +const { createMutex } = require("gatsby-core-utils/mutex") |
| 92 | + |
| 93 | +const mutex = createMutex("my-custom-mutex-key") |
| 94 | +await mutex.acquire() |
| 95 | + |
| 96 | +await fs.writeFile("pathToFile", "my custom content") |
| 97 | + |
| 98 | +await mutex.release() |
| 99 | +``` |
| 100 | + |
| 101 | +Calling `hasFeature` allows you to check if the current version of Gatsby has a certain feature. This is particularly useful for plugin authors. |
| 102 | + |
| 103 | +```js |
| 104 | +const { hasFeature } = require(`gatsby-plugin-utils`) |
| 105 | + |
| 106 | +if (!hasFeature(`image-service`)) { |
| 107 | + // You can do things like polyfill image-service here so older versions have support as well |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +**Note** - The list of features available will be added in future PRs, the above is an example of how it will be used. |
| 112 | + |
| 113 | +## Notable bugfixes & improvements |
| 114 | + |
| 115 | +- `gatsby-plugin-gatsby-cloud`: Improved UX for preview success and error notifications, via [PR #34725](https://github.com/gatsbyjs/gatsby/pull/34725) |
| 116 | +- `gatsby`: |
| 117 | + - Removal of `v8-compile-cache` for better ESM support, via [PR #34672](https://github.com/gatsbyjs/gatsby/pull/34672) |
| 118 | + - Support use of `node.slug` to match node manifests to pages for Gatsby Preview, via [PR #34790](https://github.com/gatsbyjs/gatsby/pull/34790) |
| 119 | + - Fix Content Sync when using DSG, via [PR #34799](https://github.com/gatsbyjs/gatsby/pull/34799) |
| 120 | + - Allow referencing derived types in schema customization, via [PR #34787](https://github.com/gatsbyjs/gatsby/pull/34787) |
| 121 | + - Refactor load plugin modules, via [PR #34813](https://github.com/gatsbyjs/gatsby/pull/34813) |
| 122 | + - Upgrade from lmdb-store to lmdb, via [PR #34576](https://github.com/gatsbyjs/gatsby/pull/34576) |
| 123 | +- `gatsby-source-wordpress`: Fix Safari image loading bug, via [PR #34727](https://github.com/gatsbyjs/gatsby/pull/34727) |
| 124 | +- `gatsby-core-utils`: Improvements to `fetch-remote-file`, via [PR #34758](https://github.com/gatsbyjs/gatsby/pull/34758) |
| 125 | + |
| 126 | +## Contributors |
| 127 | + |
| 128 | +A big **Thank You** to [our community who contributed][full-changelog] to this release 💜 |
| 129 | + |
| 130 | +- [kyleslie2](https://github.com/kyleslie2): Typo fix [PR #34749](https://github.com/gatsbyjs/gatsby/pull/34749) |
| 131 | +- [angeloashmore](https://github.com/angeloashmore): chore(docs): Add Prismic to `using-gatsby-plugin-image` [PR #34751](https://github.com/gatsbyjs/gatsby/pull/34751) |
| 132 | +- [paulduszak](https://github.com/paulduszak): chore(docs): Update "building a theme" tutorial [PR #34732](https://github.com/gatsbyjs/gatsby/pull/34732) |
| 133 | +- [jhcao23](https://github.com/jhcao23): docs: update typo Forestry [PR #34805](https://github.com/gatsbyjs/gatsby/pull/34805) |
| 134 | +- [VividhPandey003](https://github.com/VividhPandey003): documentation: Add Third Party Schema [PR #34820](https://github.com/gatsbyjs/gatsby/pull/34820) |
| 135 | +- [axe312ger](https://github.com/axe312ger) |
| 136 | + - refactor(gatsby-source-contentful): remove unnecessary check for existing node [PR #34829](https://github.com/gatsbyjs/gatsby/pull/34829) |
| 137 | + - fix(gatsby-source-contentful): avoid confusion of Gatsby node and Contentful node count in logs [PR #34830](https://github.com/gatsbyjs/gatsby/pull/34830) |
| 138 | + |
| 139 | +[full-changelog]: https://github.com/gatsbyjs/gatsby/compare/[email protected]@4.8.0 |
0 commit comments