Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const fetchAndCreateSingleNode = async ({
const query = getNodeQuery()

const {
helpers: { reporter },
helpers: { reporter, getNode },
pluginOptions,
} = getGatsbyApi()

Expand Down Expand Up @@ -71,7 +71,7 @@ export const fetchAndCreateSingleNode = async ({
errorContext: `Error occurred while updating a single "${singleName}" node.`,
})

const remoteNode = data[singleName]
let remoteNode = data[singleName]

if (!data || !remoteNode) {
reporter.warn(
Expand All @@ -89,6 +89,30 @@ export const fetchAndCreateSingleNode = async ({
id,
})

if (isPreview) {
const existingNode = getNode(id)

/**
* For Preview, revisions of a node type can have data that updates unecessarily
* This code block fixes that. The result being that less queries
* are invalidated in Gatsby. For example if you have a query where you're getting the latest published post using the date field, that should be static but each preview updates the date field on the node being previewed (because the revision has a new date). So if we prevent the following fields from changing, this will be less problematic.
*/
if (existingNode) {
remoteNode = {
...remoteNode,
databaseId: existingNode.databaseId,
date: existingNode.date,
dateGmt: existingNode.dateGmt,
slug: existingNode.slug,
guid: existingNode.guid,
id: existingNode.id,
link: existingNode.link,
uri: existingNode.uri,
status: existingNode.status,
}
}
}

data[singleName] = remoteNode

const { additionalNodeIds, node } = await createSingleNode({
Expand Down