-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(gatsby-source-drupal): Clone nodes before adding back references so Gatsby knows the node has changed (so knows to re-run queries) #33328
Conversation
…eferences so queries are re-run
const referencedNode = getNode(nodeID) | ||
let referencedNode | ||
if (mutateNode) { | ||
referencedNode = getNode(nodeID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the initial sourcing, it does make sense to directly mutate nodes as none of them have been created yet.
@@ -271,23 +299,9 @@ ${JSON.stringify(nodeToUpdate, null, 4)} | |||
) | |||
} | |||
}) | |||
|
|||
// see what nodes are newly referenced, and make sure to call `createNode` on them | |||
const addedReferencedNodes = _.difference( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code isn't needed as it just duplicates what handleReferences does. We now return nodes with updated backreferences from that function so we can eliminate this code.
@@ -9,16 +9,17 @@ const { | |||
|
|||
const { getOptions } = require(`./plugin-options`) | |||
|
|||
const backRefsNamesLookup = new WeakMap() | |||
const referencedNodesLookup = new WeakMap() | |||
const backRefsNamesLookup = new Map() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to regular maps w/ IDs as we're not holding consistent references to the same node object anymore.
…eferences so queries are re-run (#33328)
…eferences so queries are re-run (gatsbyjs#33328)
Big thanks to @kszot-ref for finding the root problem of the issue he was noticing with his Drupal/Gatsby site in #33285 (comment).
Fixes #33284
The bug is fairly subtle. The plugin currently updates backreferences on nodes by
directly mutating them. This means that for already existing nodes, Gatsby wasn't able
to tell that they'd changed because when it tried to compare the "new" version of the node
with the "old" version, they were the same because we'd mutated the old node object directly.
The fix is to always do a deep clone of the node object before making modifications to it
so Gatsby knows the node has changed and re-runs any pages depending on it.
I wonder now how common this issue is in other source plugins.