Skip to content

Commit

Permalink
Add another check for render doneness for validation failure
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Aug 7, 2020
1 parent 54872ed commit 7628171
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
8 changes: 8 additions & 0 deletions packages/gatsby-recipes/src/renderer/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,18 @@ const render = (recipe, cb, inputs = {}, isApply, isStream, name) => {
// If there's still nothing on the queue and we've drained the queue, that means we're done.
} else if (isDrained && queue.length === 0) {
return true
// If there's one resource & it fails validation, it doesn't go into the queue
// so we check if inFlightCache is empty & all resources have an error.
} else if (
!resources.some(r => !r.error) &&
![...inFlightCache.values()].some(a => a)
) {
return true
}

return false
}

if (isDone()) {
// Rerender with the resources and resolve the data from the cache.
emitter.emit(`done`, resources)
Expand Down
17 changes: 6 additions & 11 deletions packages/gatsby-recipes/src/validate-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ module.exports = async steps => {
}
})

try {
const firstStepPlan = await render(steps[0])
if (firstStepPlan.length) {
errors.push({
step: 0,
validationError: `Resources should not be placed in the introduction step (0)`,
})
}
} catch (e) {
// This means the first step has a syntax error which is already
// addressed above.
const firstStepPlan = await render(steps[0])
if (firstStepPlan.length) {
errors.push({
step: 0,
validationError: `Resources should not be placed in the introduction step (0)`,
})
}

return errors
Expand Down

0 comments on commit 7628171

Please sign in to comment.