Unverified Commit e83bc939 authored by Josh Story's avatar Josh Story Committed by GitHub

Instant Insights: favor reported errors over missing slots (#93709)

When we can't validate the entire render because some expected slot
wasn't rendered we report that as an error. However we do this before
checking if there were errors to report from the slots the did render.
Since conditional rendering is a thing and it might inadvertantly cause
you to not see more directly actional feedback we now prioritize
reported errors from the validation before reporting any unrendered
slots
parent 4e633139
...@@ -1338,30 +1338,14 @@ export function getNavigationDisallowedDynamicReasons( ...@@ -1338,30 +1338,14 @@ export function getNavigationDisallowedDynamicReasons(
return validationPreventingErrors return validationPreventingErrors
} }
if (!allRequiredBoundariesRendered(boundaryState)) { // Missing boundaries on their own aren't a strong signal — a parent
const { thrownErrorsOutsideBoundary } = dynamicValidation // layout may legitimately omit a slot. Run the remaining validation
const rootInstantStack = dynamicValidation.slotStacks[0] // layers first; if they find a genuine problem we'd rather surface
if (thrownErrorsOutsideBoundary.length === 0) { // that. Only fall back to the missing-boundary error when nothing
const message = `Route "${workStore.route}": Could not validate \`unstable_instant\` because the target segment was prevented from rendering for an unknown reason.` // else explains the failure (so the user is still made aware that
const error = rootInstantStack !== null ? rootInstantStack() : new Error() // validation didn't complete). When we add a markers API, the
error.name = 'Error' // marker-based variant of this check can become strict again.
error.message = message //
return [error]
} else if (thrownErrorsOutsideBoundary.length === 1) {
const message = `Route "${workStore.route}": Could not validate \`unstable_instant\` because the target segment was prevented from rendering, likely due to the following error.`
const error = rootInstantStack !== null ? rootInstantStack() : new Error()
error.name = 'Error'
error.message = message
return [error, thrownErrorsOutsideBoundary[0] as Error]
} else {
const message = `Route "${workStore.route}": Could not validate \`unstable_instant\` because the target segment was prevented from rendering, likely due to one of the following errors.`
const error = rootInstantStack !== null ? rootInstantStack() : new Error()
error.name = 'Error'
error.message = message
return [error, ...(thrownErrorsOutsideBoundary as Error[])]
}
}
// NOTE: We don't care about Suspense above body here, // NOTE: We don't care about Suspense above body here,
// we're only concerned with the validation boundary // we're only concerned with the validation boundary
if (prelude !== PreludeState.Full) { if (prelude !== PreludeState.Full) {
...@@ -1370,13 +1354,14 @@ export function getNavigationDisallowedDynamicReasons( ...@@ -1370,13 +1354,14 @@ export function getNavigationDisallowedDynamicReasons(
return dynamicErrors return dynamicErrors
} }
if (prelude === PreludeState.Empty) { if (
// If a client component suspended prevented us from rendering a shell prelude === PreludeState.Empty &&
// but didn't block validation, we don't require a prelude. !dynamicValidation.hasAllowedClientDynamicAboveBoundary &&
if (dynamicValidation.hasAllowedClientDynamicAboveBoundary) { allRequiredBoundariesRendered(boundaryState)
return [] ) {
} // If we ever get this far then we messed up the tracking of invalid
// If we ever get this far then we messed up the tracking of invalid dynamic. // dynamic. (When boundaries are missing the fallback below will
// surface a more useful error.)
return [ return [
new InvariantError( new InvariantError(
`Route "${workStore.route}" failed to render during instant validation and Next.js was unable to determine a reason.` `Route "${workStore.route}" failed to render during instant validation and Next.js was unable to determine a reason.`
...@@ -1396,6 +1381,31 @@ export function getNavigationDisallowedDynamicReasons( ...@@ -1396,6 +1381,31 @@ export function getNavigationDisallowedDynamicReasons(
return [dynamicValidation.dynamicMetadata] return [dynamicValidation.dynamicMetadata]
} }
} }
if (!allRequiredBoundariesRendered(boundaryState)) {
const { thrownErrorsOutsideBoundary } = dynamicValidation
const rootInstantStack = dynamicValidation.slotStacks[0]
if (thrownErrorsOutsideBoundary.length === 0) {
const message = `Route "${workStore.route}": Could not validate \`unstable_instant\` because the target segment was prevented from rendering for an unknown reason.`
const error = rootInstantStack !== null ? rootInstantStack() : new Error()
error.name = 'Error'
error.message = message
return [error]
} else if (thrownErrorsOutsideBoundary.length === 1) {
const message = `Route "${workStore.route}": Could not validate \`unstable_instant\` because the target segment was prevented from rendering, likely due to the following error.`
const error = rootInstantStack !== null ? rootInstantStack() : new Error()
error.name = 'Error'
error.message = message
return [error, thrownErrorsOutsideBoundary[0] as Error]
} else {
const message = `Route "${workStore.route}": Could not validate \`unstable_instant\` because the target segment was prevented from rendering, likely due to one of the following errors.`
const error = rootInstantStack !== null ? rootInstantStack() : new Error()
error.name = 'Error'
error.message = message
return [error, ...(thrownErrorsOutsideBoundary as Error[])]
}
}
// We had a non-empty prelude and there are no dynamic holes // We had a non-empty prelude and there are no dynamic holes
return [] return []
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment