Buckets:
silverwolf-x/project / packages /next /src /next-devtools /userspace /app /app-dev-overlay-error-boundary.tsx
| import React, { PureComponent, startTransition } from 'react' | |
| import { dispatcher } from 'next/dist/compiled/next-devtools' | |
| import { RuntimeErrorHandler } from '../../../client/dev/runtime-error-handler' | |
| import { ErrorBoundary } from '../../../client/components/error-boundary' | |
| import DefaultGlobalError from '../../../client/components/builtin/global-error' | |
| import type { GlobalErrorState } from '../../../client/components/app-router-instance' | |
| import { SEGMENT_EXPLORER_SIMULATED_ERROR_MESSAGE } from './segment-explorer-node' | |
| import { | |
| AppRouterContext, | |
| type AppRouterInstance, | |
| } from '../../../shared/lib/app-router-context.shared-runtime' | |
| type AppDevOverlayErrorBoundaryProps = { | |
| children: React.ReactNode | |
| globalError: GlobalErrorState | |
| } | |
| type AppDevOverlayErrorBoundaryState = { | |
| reactError: unknown | |
| } | |
| function ErroredHtml({ | |
| globalError: [GlobalError, globalErrorStyles], | |
| error, | |
| reset, | |
| unstable_retry, | |
| }: { | |
| globalError: GlobalErrorState | |
| error: unknown | |
| reset: () => void | |
| unstable_retry: () => void | |
| }) { | |
| if (!error) { | |
| return ( | |
| <html> | |
| <head /> | |
| <body /> | |
| </html> | |
| ) | |
| } | |
| return ( | |
| <ErrorBoundary errorComponent={DefaultGlobalError}> | |
| {globalErrorStyles} | |
| <GlobalError | |
| error={error} | |
| reset={reset} | |
| unstable_retry={unstable_retry} | |
| /> | |
| </ErrorBoundary> | |
| ) | |
| } | |
| export class AppDevOverlayErrorBoundary extends PureComponent< | |
| AppDevOverlayErrorBoundaryProps, | |
| AppDevOverlayErrorBoundaryState | |
| > { | |
| static contextType = AppRouterContext | |
| declare context: AppRouterInstance | null | |
| state: AppDevOverlayErrorBoundaryState = { | |
| reactError: null, | |
| } | |
| static getDerivedStateFromError(error: Error) { | |
| RuntimeErrorHandler.hadRuntimeError = true | |
| return { | |
| reactError: error, | |
| } | |
| } | |
| componentDidCatch(err: Error) { | |
| if ( | |
| process.env.NODE_ENV === 'development' && | |
| err.message === SEGMENT_EXPLORER_SIMULATED_ERROR_MESSAGE | |
| ) { | |
| return | |
| } | |
| dispatcher.openErrorOverlay() | |
| } | |
| unstable_retry = () => { | |
| startTransition(() => { | |
| this.context?.refresh() | |
| this.reset() | |
| }) | |
| } | |
| reset = () => { | |
| this.setState({ reactError: null }) | |
| } | |
| render() { | |
| const { children, globalError } = this.props | |
| const { reactError } = this.state | |
| const fallback = ( | |
| <ErroredHtml | |
| globalError={globalError} | |
| error={reactError} | |
| reset={this.reset} | |
| unstable_retry={this.unstable_retry} | |
| /> | |
| ) | |
| return reactError !== null ? fallback : children | |
| } | |
| } | |
Xet Storage Details
- Size:
- 2.56 kB
- Xet hash:
- ad6981fb4c9546cec71ec4c5103e3a025765edd9b7e4a60407cf751f1c883c60
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.