diff --git a/packages/next/src/client/components/errors/attach-hydration-error-state.ts b/packages/next/src/client/components/errors/attach-hydration-error-state.ts
index ef98ddf547a8a..9d78b7b1fd4ce 100644
--- a/packages/next/src/client/components/errors/attach-hydration-error-state.ts
+++ b/packages/next/src/client/components/errors/attach-hydration-error-state.ts
@@ -1,5 +1,6 @@
import {
getDefaultHydrationErrorMessage,
+ isHydrationError,
testReactHydrationWarning,
} from '../is-hydration-error'
import {
@@ -13,24 +14,42 @@ export function attachHydrationErrorState(error: Error) {
)
let parsedHydrationErrorState: typeof hydrationErrorState = {}
const isHydrationWarning = testReactHydrationWarning(error.message)
+ const isHydrationRuntimeError = isHydrationError(error)
// If the reactHydrationDiffSegments exists
// and the diff (reactHydrationDiffSegments[1]) exists
// e.g. the hydration diff log error.
- if (reactHydrationDiffSegments && reactHydrationDiffSegments[1]) {
+ if (reactHydrationDiffSegments) {
+ const diff = reactHydrationDiffSegments[1]
parsedHydrationErrorState = {
...(error as any).details,
...hydrationErrorState,
- warning: hydrationErrorState.warning || [
- getDefaultHydrationErrorMessage(),
- ],
+ // If diff is present in error, we don't need to pick up the console logged warning.
+ // - if hydration error has diff, and is not hydration diff log, then it's a normal hydration error.
+ // - if hydration error no diff, then leverage the one from the hydration diff log.
+
+ warning: (diff && !isHydrationWarning
+ ? null
+ : hydrationErrorState.warning) || [getDefaultHydrationErrorMessage()],
+ // When it's hydration diff log, do not show notes section.
+ // This condition is only for the 1st squashed error.
notes: isHydrationWarning ? '' : reactHydrationDiffSegments[0],
- reactOutputComponentDiff: reactHydrationDiffSegments[1],
+ reactOutputComponentDiff: diff,
}
// Cache the `reactOutputComponentDiff` into hydrationErrorState.
// This is only required for now when we still squashed the hydration diff log into hydration error.
// Once the all error is logged to dev overlay in order, this will go away.
- hydrationErrorState.reactOutputComponentDiff =
- parsedHydrationErrorState.reactOutputComponentDiff
+ if (!hydrationErrorState.reactOutputComponentDiff && diff) {
+ hydrationErrorState.reactOutputComponentDiff = diff
+ }
+ // If it's hydration runtime error that doesn't contain the diff, combine the diff from the cached hydration diff.
+ if (
+ !diff &&
+ isHydrationRuntimeError &&
+ hydrationErrorState.reactOutputComponentDiff
+ ) {
+ parsedHydrationErrorState.reactOutputComponentDiff =
+ hydrationErrorState.reactOutputComponentDiff
+ }
} else {
// Normal runtime error, where it doesn't contain the hydration diff.
diff --git a/packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/errors/error-overlay-pagination/error-overlay-pagination.tsx b/packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/errors/error-overlay-pagination/error-overlay-pagination.tsx
index ddb75de22f554..209568feb78f5 100644
--- a/packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/errors/error-overlay-pagination/error-overlay-pagination.tsx
+++ b/packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/errors/error-overlay-pagination/error-overlay-pagination.tsx
@@ -118,6 +118,7 @@ export function ErrorOverlayPagination({
disabled={activeIdx === 0}
aria-disabled={activeIdx === 0}
onClick={handlePrevious}
+ data-nextjs-dialog-error-previous
className="error-overlay-pagination-button"
>
- {activeIdx + 1}/
+ {activeIdx + 1}/
{/* Display 1 out of 1 if there are no errors (e.g. for build errors). */}
{readyErrors.length || 1}
@@ -139,6 +140,7 @@ export function ErrorOverlayPagination({
disabled={activeIdx >= readyErrors.length - 1}
aria-disabled={activeIdx >= readyErrors.length - 1}
onClick={handleNext}
+ data-nextjs-dialog-error-next
className="error-overlay-pagination-button"
>
=