Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
LekoArts committed Dec 9, 2021
2 parents e72a11a + 6b28b69 commit c927b9d
Show file tree
Hide file tree
Showing 64 changed files with 549 additions and 157 deletions.
6 changes: 3 additions & 3 deletions deprecated-packages/gatsby-recipes/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-recipes",
"description": "Core functionality for Gatsby Recipes",
"version": "1.4.0-next.0",
"version": "1.4.0-next.1",
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
Expand Down Expand Up @@ -31,8 +31,8 @@
"express": "^4.17.1",
"express-graphql": "^0.12.0",
"fs-extra": "^10.0.0",
"gatsby-core-utils": "^3.4.0-next.0",
"gatsby-telemetry": "^3.4.0-next.0",
"gatsby-core-utils": "^3.4.0-next.1",
"gatsby-telemetry": "^3.4.0-next.1",
"glob": "^7.1.6",
"graphql": "^15.4.0",
"graphql-compose": "~7.25.0",
Expand Down
101 changes: 101 additions & 0 deletions docs/docs/how-to/local-development/debugging-missing-data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: Debugging Missing or Stale Data Fields on Nodes
---

## Overview of `LMDB` datastore behavior changes

In Gatsby 3 we introduced a new data store called `LMDB` (enabled with `LMDB_STORE` and/or `PARALLEL_QUERY_RUNNING` flags). In Gatsby 4 it became the default data store. It allows Gatsby to execute data layer related processing outside of the main build process and enables Gatsby to run queries in multiple processes as well as support additional rendering strategies ([DSG](/docs/reference/rendering-options/deferred-static-generation/) and [SSR](/docs/reference/rendering-options/server-side-rendering/)).

In a lot of cases that change is completely invisible to users, but there are cases where things behave differently.

Direct node mutations in various API lifecycles are not persisted anymore. In previous Gatsby versions it did work because source of truth for the data layer was directly in Node.js memory, so mutating node was in fact mutating source of truth. Now Gatsby edits data it receives from the database, so unless it explicitly upserts data to this database after edits, those edits will not be persisted (even for same the same build).

Common errors when doing swap to `LMDB` will be that some fields don't exist anymore or are `null`/`undefined` when trying to execute GraphQL queries.

## Diagnostic mode

Gatsby (starting with version 4.4) can detect those node mutations. Unfortunately it adds measurable overhead so it isn't enabled by default. You can opt into it when you see data related issues (particularly when you didn't have this issue before using `LMDB`). To enable diagnostic mode:

- Use truthy environment variable `GATSBY_DETECT_NODE_MUTATIONS`:
```
GATSBY_DETECT_NODE_MUTATIONS=1 gatsby build
```
- Or use `DETECT_NODE_MUTATIONS` config flag:
```javascript:title=gatsby-config.js
module.exports = {
flags: {
DETECT_NODE_MUTATIONS: true,
},
}
```

Example diagnostic message you might see:

```
warn Node mutation detected
File <rootDir>/plugins/transform/gatsby-node.js:4:20
2 | if (node.internal.type === `Test`) {
3 | // console.log(`[Mutating node in onCreateNode]`)
> 4 | node.nested.a2 = `edited`
| ^
5 | }
6 | }
7 |
Stack trace:
at Object.exports.onCreateNode (<rootDir>/plugins/transform/gatsby-node.js:4:20)
at runAPI (<rootDir>/node_modules/gatsby/src/utils/api-runner-node.js:462:22)
at Promise.catch.decorateEvent.pluginName
(<rootDir>/node_modules/gatsby/src/utils/api-runner-node.js:613:13)
at Promise._execute
... Rest of Stacktrace
```

It will point you to the code that is trying to mutate nodes. Note that it might also point to installed plugins in which case you should notify the plugin maintainer about it.

**Please Note:** Be sure to stop using this mode once you find and handle all problematic code paths as it will decrease performance.

## Migration

### Mutating a node in `onCreateNode`

Instead of mutating nodes directly, `createNodeField` action should be used instead. This way Gatsby will update the source of truth (to actually update the node in the datastore). `createNodeField` will create that additional field under `fields.fieldName`. If you want to preserve schema shape, so that additional field is on the root of a node, you can use schema customization.

```diff
const { createRemoteFileNode } = require(`gatsby-source-filesystem`)

exports.onCreateNode = async ({
node, // the node that was just created
- actions: { createNode },
+ actions: { createNode, createNodeField },
createNodeId,
getCache,
}) => {
if (node.internal.type === `SomeNodeType`) {
const fileNode = await createRemoteFileNode({
// the url of the remote image to generate a node for
url: node.imgUrl,
parentNodeId: node.id,
createNode,
createNodeId,
getCache,
})

if (fileNode) {
- node.localFile___NODE = fileNode.id
+ createNodeField({ node, name: 'localFile', value: fileNode.id })
}
}
}
+
+exports.createSchemaCustomization = ({ actions }) => {
+ const { createTypes } = actions
+
+ createTypes(`
+ type SomeNodeType implements Node {
+ localFile: File @link(from: "fields.localFile")
+ }
+ `)
+}
```
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const resolveGatsbyImageData = async (image, options) => {
pluginName: `gatsby-source-example`,
sourceMetadata,
filename,
placeholderURL
placeholderURL,
generateImageSource,
options,
}
Expand Down
3 changes: 1 addition & 2 deletions docs/docs/reference/release-notes/migrating-from-v3-to-v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,7 @@ This was never an intended feature of Gatsby and is considered an anti-pattern (
Starting with v4 Gatsby introduces a persisted storage for nodes and thus this pattern will no longer work
because nodes are persisted after `createNode` call and all direct mutations after that will be lost.

Unfortunately it is hard to detect it automatically (without sacrificing performance), so we recommend you to
check your code to ensure you don't mutate nodes directly.
Gatsby provides diagnostic mode to detect those direct mutations, unfortunately it has noticeable performance overhead so we don't enable it by default. See [Debugging missing data](/docs/how-to/local-development/debugging-missing-data/) for more details on it.

Gatsby provides several actions available in `sourceNodes` and `onCreateNode` APIs to use instead:

Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-remove-graphql-queries/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-plugin-remove-graphql-queries",
"version": "4.4.0-next.0",
"version": "4.4.0-next.1",
"author": "Jason Quense <monastic.panic@gmail.com>",
"repository": {
"type": "git",
Expand All @@ -10,7 +10,7 @@
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/babel-plugin-remove-graphql-queries#readme",
"dependencies": {
"@babel/runtime": "^7.15.4",
"gatsby-core-utils": "^3.4.0-next.0"
"gatsby-core-utils": "^3.4.0-next.1"
},
"devDependencies": {
"@babel/cli": "^7.15.4",
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-preset-gatsby/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-preset-gatsby",
"version": "2.4.0-next.0",
"version": "2.4.0-next.1",
"author": "Philipp Spiess <hello@philippspiess.com>",
"repository": {
"type": "git",
Expand All @@ -22,8 +22,8 @@
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-macros": "^2.8.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"gatsby-core-utils": "^3.4.0-next.0",
"gatsby-legacy-polyfills": "^2.4.0-next.0"
"gatsby-core-utils": "^3.4.0-next.1",
"gatsby-legacy-polyfills": "^2.4.0-next.1"
},
"peerDependencies": {
"@babel/core": "^7.11.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/create-gatsby/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-gatsby",
"version": "2.4.0-next.0",
"version": "2.4.0-next.1",
"main": "lib/index.js",
"bin": "cli.js",
"license": "MIT",
Expand Down Expand Up @@ -28,7 +28,7 @@
"eslint": "^7.32.0",
"execa": "^5.1.1",
"fs-extra": "^10.0.0",
"gatsby-plugin-utils": "^2.4.0-next.0",
"gatsby-plugin-utils": "^2.4.0-next.1",
"joi": "^17.4.2",
"microbundle": "^0.14.2",
"node-fetch": "^2.6.6",
Expand Down
8 changes: 4 additions & 4 deletions packages/gatsby-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-cli",
"description": "Gatsby command-line interface for creating new sites and running Gatsby commands",
"version": "4.4.0-next.0",
"version": "4.4.0-next.1",
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"bin": {
"gatsby": "cli.js"
Expand All @@ -20,13 +20,13 @@
"common-tags": "^1.8.2",
"configstore": "^5.0.1",
"convert-hrtime": "^3.0.0",
"create-gatsby": "^2.4.0-next.0",
"create-gatsby": "^2.4.0-next.1",
"envinfo": "^7.8.1",
"execa": "^5.1.1",
"fs-exists-cached": "^1.0.0",
"fs-extra": "^10.0.0",
"gatsby-core-utils": "^3.4.0-next.0",
"gatsby-telemetry": "^3.4.0-next.0",
"gatsby-core-utils": "^3.4.0-next.1",
"gatsby-telemetry": "^3.4.0-next.1",
"hosted-git-info": "^3.0.8",
"is-valid-path": "^0.1.1",
"joi": "^17.4.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-codemods/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-codemods",
"version": "3.4.0-next.0",
"version": "3.4.0-next.1",
"description": "A collection of codemod scripts for use with JSCodeshift that help migrate to newer versions of Gatsby.",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-core-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-core-utils",
"version": "3.4.0-next.0",
"version": "3.4.0-next.1",
"description": "A collection of gatsby utils used in different gatsby packages",
"keywords": [
"gatsby",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-design-tokens/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-design-tokens",
"version": "4.4.0-next.0",
"version": "4.4.0-next.1",
"description": "Gatsby Design Tokens",
"main": "dist/index.js",
"module": "dist/index.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-dev-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-dev-cli",
"description": "CLI helpers for contributors working on Gatsby",
"version": "4.4.0-next.0",
"version": "4.4.0-next.1",
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"bin": {
"gatsby-dev": "./dist/index.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-legacy-polyfills/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-legacy-polyfills",
"description": "Polyfills for legacy browsers",
"version": "2.4.0-next.0",
"version": "2.4.0-next.1",
"main": "dist/polyfills.js",
"author": "Ward Peeters <ward@gatsbyjs.com>",
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-legacy-polyfills#readme",
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-page-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-page-utils",
"version": "2.4.0-next.0",
"version": "2.4.0-next.1",
"description": "Gatsby library that helps creating pages",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -26,7 +26,7 @@
"bluebird": "^3.7.2",
"chokidar": "^3.5.2",
"fs-exists-cached": "^1.0.0",
"gatsby-core-utils": "^3.4.0-next.0",
"gatsby-core-utils": "^3.4.0-next.1",
"glob": "^7.2.0",
"lodash": "^4.17.21",
"micromatch": "^4.0.4"
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-plugin-benchmark-reporting/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-plugin-benchmark-reporting",
"description": "Gatsby Benchmark Reporting",
"version": "2.4.0-next.0",
"version": "2.4.0-next.1",
"author": "Peter van der Zee <pvdz@github>",
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
Expand All @@ -21,7 +21,7 @@
"dependencies": {
"@babel/runtime": "^7.15.4",
"fast-glob": "^3.2.7",
"gatsby-core-utils": "^3.4.0-next.0",
"gatsby-core-utils": "^3.4.0-next.1",
"node-fetch": "^2.6.6"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-plugin-cxs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-plugin-cxs",
"description": "Gatsby plugin to add SSR support for ctx",
"version": "4.4.0-next.0",
"version": "4.4.0-next.1",
"author": "Chen-Tai Hou <ctxhou@gmail.com>",
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
Expand All @@ -15,7 +15,7 @@
"babel-preset-gatsby-package": "^2.4.0-next.0",
"cross-env": "^7.0.3",
"cxs": "^6.2.0",
"gatsby-plugin-utils": "^2.4.0-next.0"
"gatsby-plugin-utils": "^2.4.0-next.1"
},
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-cxs#readme",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-emotion/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-plugin-emotion",
"description": "Gatsby plugin to add support for Emotion",
"version": "7.4.0-next.0",
"version": "7.4.0-next.1",
"author": "Tegan Churchill <churchill.tegan@gmail.com>",
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
Expand Down

0 comments on commit c927b9d

Please sign in to comment.