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

[DevOverlay] Display Correct Number of Errors on Indicator #75395

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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export default function ReactDevOverlay({
children: React.ReactNode
}) {
const [isErrorOverlayOpen, setIsErrorOverlayOpen] = useState(false)
const { readyErrors } = useErrorHook({ errors: state.errors, isAppDir: true })
const { readyErrors, totalErrorCount } = useErrorHook({
state,
isAppDir: true,
})

const devOverlay = (
<ShadowPortal>
Expand All @@ -33,7 +36,7 @@ export default function ReactDevOverlay({

<DevToolsIndicator
state={state}
readyErrorsLength={readyErrors.length}
errorCount={totalErrorCount}
setIsErrorOverlayOpen={setIsErrorOverlayOpen}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,31 @@ const state: OverlayState = {

export const NoErrors: Story = {
args: {
readyErrorsLength: 0,
errorCount: 0,
state,
setIsErrorOverlayOpen: () => {},
},
}

export const SingleError: Story = {
args: {
readyErrorsLength: 1,
errorCount: 1,
state,
setIsErrorOverlayOpen: () => {},
},
}

export const MultipleErrors: Story = {
args: {
readyErrorsLength: 3,
errorCount: 3,
state,
setIsErrorOverlayOpen: () => {},
},
}

export const WithStaticIndicator: Story = {
args: {
readyErrorsLength: 3,
errorCount: 3,
state: {
...state,
staticIndicator: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { MODIFIERS } from '../../../hooks/use-keyboard-shortcut'

export function DevToolsIndicator({
state,
readyErrorsLength,
errorCount,
setIsErrorOverlayOpen,
}: {
state: OverlayState
readyErrorsLength: number
errorCount: number
setIsErrorOverlayOpen: Dispatch<SetStateAction<boolean>>
}) {
const [isDevToolsIndicatorOpen, setIsDevToolsIndicatorOpen] = useState(true)
Expand All @@ -36,7 +36,7 @@ export function DevToolsIndicator({
isDevToolsIndicatorOpen && (
<DevToolsPopover
semver={state.versionInfo.installed}
issueCount={readyErrorsLength}
issueCount={errorCount}
isStaticRoute={state.staticIndicator}
hide={() => {
setIsDevToolsIndicatorOpen(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ReadyRuntimeError } from '../../helpers/get-error-by-type'
import type {
OverlayState,
UnhandledErrorAction,
UnhandledRejectionAction,
} from '../../../../shared'
Expand Down Expand Up @@ -33,12 +34,14 @@ function getErrorSignature(ev: SupportedErrorEvent): string {
}

export function useErrorHook({
errors,
state,
isAppDir,
}: {
errors: SupportedErrorEvent[]
state: OverlayState
isAppDir: boolean
}) {
const { errors, rootLayoutMissingTags, buildError } = state

const [lookups, setLookups] = useState<{
[eventId: string]: ReadyRuntimeError
}>({})
Expand Down Expand Up @@ -99,5 +102,14 @@ export function useErrorHook({

return {
readyErrors,
// Total number of errors are based on the priority that
// will be displayed. Since build error and root layout
// missing tags won't be dismissed until resolved, the
// total number of errors may be fixed to their length.
totalErrorCount: rootLayoutMissingTags?.length
? rootLayoutMissingTags.length
: !!buildError
? 1
: errors.length,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export default function ReactDevOverlay({ children }: ReactDevOverlayProps) {
hasBuildError,
} = usePagesReactDevOverlay()

const { readyErrors } = useErrorHook({
errors: state.errors,
const { readyErrors, totalErrorCount } = useErrorHook({
state,
isAppDir: false,
})

Expand All @@ -50,7 +50,7 @@ export default function ReactDevOverlay({ children }: ReactDevOverlayProps) {

<DevToolsIndicator
state={state}
readyErrorsLength={readyErrors.length}
errorCount={totalErrorCount}
setIsErrorOverlayOpen={setIsErrorOverlayOpen}
/>

Expand Down
Loading