Skip to content

Commit

Permalink
Fix dynamic tracking in dev (vercel#71867)
Browse files Browse the repository at this point in the history
The second render should not use the first render's abort signal to
determine trackable nature of observed errors
  • Loading branch information
gnoff authored and stipsan committed Nov 6, 2024
1 parent 5169e1b commit a88bd00
Showing 1 changed file with 43 additions and 23 deletions.
66 changes: 43 additions & 23 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2055,27 +2055,6 @@ async function spawnDynamicValidationInDev(
let clientDynamicTracking = createDynamicTrackingState(false)
let dynamicValidation = createDynamicValidationState()

function SSROnError(err: unknown, errorInfo?: ErrorInfo) {
if (
isPrerenderInterruptedError(err) ||
firstAttemptServerController.signal.aborted
) {
const componentStack: string | undefined = (errorInfo as any)
.componentStack
if (typeof componentStack === 'string' && err instanceof Error) {
trackAllowedDynamicAccess(
route,
componentStack,
dynamicValidation,
serverDynamicTracking,
clientDynamicTracking
)
}
return undefined
}
return undefined
}

const firstAttemptClientController = new AbortController()
const firstAttemptClientPrerenderStore: PrerenderStore = {
type: 'prerender',
Expand Down Expand Up @@ -2116,7 +2095,27 @@ async function spawnDynamicValidationInDev(
/>,
{
signal: firstAttemptClientController.signal,
onError: SSROnError,
onError: (err: unknown, errorInfo: ErrorInfo) => {
if (
isPrerenderInterruptedError(err) ||
firstAttemptServerController.signal.aborted
) {
const componentStack: string | undefined = (errorInfo as any)
.componentStack
if (
typeof componentStack === 'string' &&
err instanceof Error
) {
trackAllowedDynamicAccess(
route,
componentStack,
dynamicValidation,
serverDynamicTracking,
clientDynamicTracking
)
}
}
},
}
)
.catch(() => {})
Expand Down Expand Up @@ -2185,7 +2184,28 @@ async function spawnDynamicValidationInDev(
/>,
{
signal: secondAttemptClientController.signal,
onError: SSROnError,
onError: (err: unknown, errorInfo: ErrorInfo) => {
if (
isPrerenderInterruptedError(err) ||
secondAttemptClientController.signal.aborted
) {
const componentStack: string | undefined = (
errorInfo as any
).componentStack
if (
typeof componentStack === 'string' &&
err instanceof Error
) {
trackAllowedDynamicAccess(
route,
componentStack,
dynamicValidation,
serverDynamicTracking,
clientDynamicTracking
)
}
}
},
}
)
.catch(() => {})
Expand Down

0 comments on commit a88bd00

Please sign in to comment.