-
Notifications
You must be signed in to change notification settings - Fork 27.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
51 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
.../src/client/components/react-dev-overlay/internal/helpers/attach-hydration-error-state.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
isHydrationError, | ||
getDefaultHydrationErrorMessage, | ||
} from '../../../is-hydration-error' | ||
import { | ||
hydrationErrorState, | ||
getReactHydrationDiffSegments, | ||
} from './hydration-error-info' | ||
|
||
export function attachHydrationErrorState(error: Error) { | ||
if ( | ||
isHydrationError(error) && | ||
!error.message.includes( | ||
'https://nextjs.org/docs/messages/react-hydration-error' | ||
) | ||
) { | ||
const reactHydrationDiffSegments = getReactHydrationDiffSegments( | ||
error.message | ||
) | ||
let parsedHydrationErrorState: typeof hydrationErrorState = {} | ||
if (reactHydrationDiffSegments) { | ||
parsedHydrationErrorState = { | ||
...(error as any).details, | ||
...hydrationErrorState, | ||
warning: hydrationErrorState.warning || [ | ||
getDefaultHydrationErrorMessage(), | ||
], | ||
notes: reactHydrationDiffSegments[0], | ||
reactOutputComponentDiff: reactHydrationDiffSegments[1], | ||
} | ||
} else { | ||
// If there's any extra information in the error message to display, | ||
// append it to the error message details property | ||
if (hydrationErrorState.warning) { | ||
// The patched console.error found hydration errors logged by React | ||
// Append the logged warning to the error message | ||
parsedHydrationErrorState = { | ||
...(error as any).details, | ||
// It contains the warning, component stack, server and client tag names | ||
...hydrationErrorState, | ||
} | ||
} | ||
error.message += | ||
'\nSee more info here: https://nextjs.org/docs/messages/react-hydration-error' | ||
} | ||
;(error as any).details = parsedHydrationErrorState | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters