-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up
react-dev-overlay
before fork (#74016)
Clean up `react-dev-overlay/` before forking for new UI. - Ported `pages/ReactDevOverlay/tsx` logic to a hook. - Moved `client-entry.tsx` to `app/` as it's only used in app router. Closes NDX-590
- Loading branch information
1 parent
12a03ab
commit 62c2f74
Showing
4 changed files
with
68 additions
and
44 deletions.
There are no files selected for viewing
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
8 changes: 4 additions & 4 deletions
8
...onents/react-dev-overlay/client-entry.tsx → ...ts/react-dev-overlay/app/client-entry.tsx
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
53 changes: 53 additions & 0 deletions
53
packages/next/src/client/components/react-dev-overlay/pages/hooks.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,53 @@ | ||
import type { ErrorType } from './ReactDevOverlay' | ||
import React from 'react' | ||
import * as Bus from './bus' | ||
import { useErrorOverlayReducer } from '../shared' | ||
|
||
const shouldPreventDisplay = ( | ||
errorType?: ErrorType | null, | ||
preventType?: ErrorType[] | null | ||
) => { | ||
if (!preventType || !errorType) { | ||
return false | ||
} | ||
return preventType.includes(errorType) | ||
} | ||
|
||
export const usePagesReactDevOverlay = ( | ||
preventDisplay: ErrorType[] | undefined | ||
) => { | ||
const [state, dispatch] = useErrorOverlayReducer() | ||
|
||
React.useEffect(() => { | ||
Bus.on(dispatch) | ||
return function () { | ||
Bus.off(dispatch) | ||
} | ||
}, [dispatch]) | ||
|
||
const onComponentError = React.useCallback( | ||
(_error: Error, _componentStack: string | null) => { | ||
// TODO: special handling | ||
}, | ||
[] | ||
) | ||
|
||
const hasBuildError = state.buildError != null | ||
const hasRuntimeErrors = Boolean(state.errors.length) | ||
const errorType = hasBuildError | ||
? 'build' | ||
: hasRuntimeErrors | ||
? 'runtime' | ||
: null | ||
const isMounted = errorType !== null | ||
|
||
const displayPrevented = shouldPreventDisplay(errorType, preventDisplay) | ||
return { | ||
isMounted, | ||
displayPrevented, | ||
hasBuildError, | ||
hasRuntimeErrors, | ||
state, | ||
onComponentError, | ||
} | ||
} |