Skip to content

Commit

Permalink
Fix dynamic tracking in dev
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 committed Oct 25, 2024
1 parent 38c3e83 commit 04acd37
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 04acd37

Please sign in to comment.