gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.3k stars 10.31k forks source link

gatsby-source-drupal: Incremental build - adding a backlink to a node is not enough to rerun page queries related to it #33284

Closed kszot-ref closed 3 years ago

kszot-ref commented 3 years ago

Preliminary Checks

Description

Example scenario:

The end result is that page-data.json for that page (office) has stale data, so it's not rebuilt properly.

In our use case the backlinks are used to display a list of vacancies on an office page, and although the backlink is created fine in the plugin, that's not enough to rebuild the page, so altough the graphql data is updated properly, the page uses old data.

I was able to check the node before it was passed on to the "createNode" function with a debugger. Everything seemed fine there. But even manually changing the value of one of the fields (before the contentDigest is genererated) didn't cause page query reruns. I suspect this might be an issue that instead of creating a new object with copied data, the plugin is modifying an object that it got through the "getNode" function. After this I've updated this "node--office" in drupal (didn't change any data, just saved it), and the next build picked that up properly and rerun the queries - the data didn't change, but the "createNode" method got a different object with the same fields which was enough to cause an update.

Reproduction Link

-

Expected Result

Office queries would be rerun.

Actual Result

Office queries aren't rerun.

Environment

System:
    OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.17.3 - ~/.nvm/versions/node/v14.17.3/bin/node
    Yarn: 1.22.10 - /mnt/c/Program Files/nodejs/yarn
    npm: 6.14.13 - ~/.nvm/versions/node/v14.17.3/bin/npm
  npmPackages:
    gatsby: ^3.10.2 => 3.10.2
    gatsby-background-image: ^1.5.3 => 1.5.3
    gatsby-plugin-create-client-paths: ^3.10.0 => 3.10.0
    gatsby-plugin-emotion: ^6.10.0 => 6.10.0
    gatsby-plugin-google-tagmanager: ^3.10.0 => 3.10.0
    gatsby-plugin-image: ^1.10.1 => 1.10.1
    gatsby-plugin-loadable-components-ssr: ^3.2.0 => 3.2.0
    gatsby-plugin-manifest: ^3.10.0 => 3.10.0
    gatsby-plugin-meta-redirect: ^1.1.1 => 1.1.1
    gatsby-plugin-react-helmet: ^4.10.0 => 4.10.0
    gatsby-plugin-react-helmet-canonical-urls: ^1.4.0 => 1.4.0
    gatsby-plugin-robots-txt: ^1.6.8 => 1.6.8
    gatsby-plugin-sass: ^4.10.0 => 4.10.0
    gatsby-plugin-sharp: ^3.10.2 => 3.10.2
    gatsby-plugin-sitemap: ^4.6.0 => 4.6.0
    gatsby-plugin-typegen: ^2.2.4 => 2.2.4
    gatsby-plugin-use-query-params: ^1.0.1 => 1.0.1
    gatsby-plugin-webpack-bundle-analyser-v2: ^1.1.24 => 1.1.24
    gatsby-query-params: ^1.2.1 => 1.2.1
    gatsby-source-drupal: ^4.14.0 => 4.14.0
    gatsby-source-filesystem: ^3.10.0 => 3.10.0
    gatsby-transformer-sharp: ^3.10.0 => 3.10.0

Config Flags

No response

kszot-ref commented 3 years ago

We've went through the code with Kyle, so I've got a few tips where to look to debug this issue. During the call we didn't pinpoint it, but I've tried again the next day.

I've went through the node creation process with a debugger and came to a conclusion that this is indeed an issue inside the gatsby-source-drupal plugin.

To create a backlink for a referenced node, the plugin does the following steps:

https://github.com/gatsbyjs/gatsby/blob/08c5b2a55559fd1419222ae6cb5a7d3c1e2a098d/packages/gatsby/src/utils/nodes.ts#L9-L16

When the code reaches this point, it gets the node from the datastore, but the issue is that data was modified inplace, the updated values are already in there. So it actually compares the new contentDigest with the already updated contentDigest, which means that the code thinks that the node didn't update at all, as in this scenario they will always be the same.

obraz