Skip to content

Commit 48d4069

Browse files
authored
fix(gatsby-source-wordpress): fix preview issues (#37492)
* add fallback array to prevent errors when cachedNodeIds aren't passed * if there's a token we're previewing - also await non node root fields for previews
1 parent c288dd5 commit 48d4069

File tree

2 files changed

+7
-12
lines changed
  • packages/gatsby-source-wordpress/src/steps/source-nodes

2 files changed

+7
-12
lines changed

packages/gatsby-source-wordpress/src/steps/source-nodes/index.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,19 @@ import { sourcePreviews } from "~/steps/preview"
1212
const sourceNodes: Step = async helpers => {
1313
const { cache, webhookBody, refetchAll } = helpers
1414

15+
// fetch non-node root fields such as settings.
16+
// For now, we're refetching them on every build
17+
const nonNodeRootFieldsPromise = fetchAndCreateNonNodeRootFields()
18+
1519
// if this is a preview we want to process it and return early
16-
if (webhookBody.preview) {
20+
if (webhookBody.token && webhookBody.userDatabaseId) {
1721
await sourcePreviews(helpers)
18-
22+
await nonNodeRootFieldsPromise
1923
return
2024
}
21-
// if it's not a preview but we have a token
22-
// we should source any pending previews then continue sourcing
23-
else if (webhookBody.token && webhookBody.userDatabaseId) {
24-
await sourcePreviews(helpers)
25-
}
2625

2726
const now = Date.now()
2827

29-
// fetch non-node root fields such as settings.
30-
// For now, we're refetching them on every build
31-
const nonNodeRootFieldsPromise = fetchAndCreateNonNodeRootFields()
32-
3328
const lastCompletedSourceTime =
3429
webhookBody.refreshing && webhookBody.since
3530
? webhookBody.since

packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/update.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const fetchAndCreateSingleNode = async ({
2424
singleName,
2525
id,
2626
actionType,
27-
cachedNodeIds,
27+
cachedNodeIds = [],
2828
token = null,
2929
isPreview = false,
3030
isDraft = false,

0 commit comments

Comments
 (0)