Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: merge the same util to detect nextjs navigation errors #67672

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/next/src/client/components/is-next-router-error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { isNotFoundError } from './not-found'
import { isRedirectError } from './redirect'

/**
* Returns true if the error is a navigation signal error. These errors are
* thrown by user code to perform navigation operations and interrupt the React
* render.
*/
export function isNextRouterError(error: any): boolean {
return (
error && error.digest && (isRedirectError(error) || isNotFoundError(error))
)
return isRedirectError(error) || isNotFoundError(error)
}
4 changes: 2 additions & 2 deletions packages/next/src/export/helpers/is-dynamic-usage-error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isDynamicServerError } from '../../client/components/hooks-server-context'
import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
import { isNavigationSignalError } from './is-navigation-signal-error'
import { isNextRouterError } from '../../client/components/is-next-router-error'

export const isDynamicUsageError = (err: unknown) =>
isDynamicServerError(err) ||
isBailoutToCSRError(err) ||
isNavigationSignalError(err)
isNextRouterError(err)
10 changes: 0 additions & 10 deletions packages/next/src/export/helpers/is-navigation-signal-error.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/next/src/server/app-render/create-error-handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { formatServerError } from '../../lib/format-server-error'
import { SpanStatusCode, getTracer } from '../lib/trace/tracer'
import { isAbortError } from '../pipe-readable'
import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
import { isNavigationSignalError } from '../../export/helpers/is-navigation-signal-error'
import { isDynamicServerError } from '../../client/components/hooks-server-context'
import { isNextRouterError } from '../../client/components/is-next-router-error'

declare global {
var __next_log_error__: undefined | ((err: unknown) => void)
Expand Down Expand Up @@ -66,7 +66,7 @@ export function createErrorHandler({
if (isBailoutToCSRError(err)) return err.digest

// If this is a navigation error, we don't need to log the error.
if (isNavigationSignalError(err)) return err.digest
if (isNextRouterError(err)) return err.digest

if (!digestErrorsMap.has(digest)) {
digestErrorsMap.set(digest, err)
Expand Down
Loading