Skip to content

Commit 597faf7

Browse files
committed
[dev-overlay] Move render indicator into Dev Overlay state
Same as for build indicator. The sync update avoided is especially nice since it used to happen during navigation where we don't want to interfere with the update priority.
1 parent e6eedf7 commit 597faf7

File tree

9 files changed

+54
-62
lines changed

9 files changed

+54
-62
lines changed

packages/next/src/client/components/react-dev-overlay/app/app-dev-overlay.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import type { GlobalErrorComponent } from '../../global-error'
77

88
import { useCallback } from 'react'
9+
import { createContext } from 'react'
910
import { AppDevOverlayErrorBoundary } from './app-dev-overlay-error-boundary'
1011
import { FontStyles } from '../font/font-styles'
1112
import { DevOverlay } from '../ui/dev-overlay'
@@ -15,6 +16,10 @@ function getSquashedHydrationErrorDetails() {
1516
return null
1617
}
1718

19+
export const AppDevOverlayDispatchContext =
20+
createContext<OverlayDispatch | null>(null)
21+
AppDevOverlayDispatchContext.displayName = 'AppDevOverlayDispatchContext'
22+
1823
export function AppDevOverlay({
1924
state,
2025
dispatch,
@@ -31,7 +36,7 @@ export function AppDevOverlay({
3136
}, [dispatch])
3237

3338
return (
34-
<>
39+
<AppDevOverlayDispatchContext value={dispatch}>
3540
<AppDevOverlayErrorBoundary
3641
globalError={globalError}
3742
onError={openOverlay}
@@ -47,6 +52,6 @@ export function AppDevOverlay({
4752
getSquashedHydrationErrorDetails={getSquashedHydrationErrorDetails}
4853
/>
4954
</>
50-
</>
55+
</AppDevOverlayDispatchContext>
5156
)
5257
}

packages/next/src/client/components/react-dev-overlay/shared.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface OverlayState {
2323
versionInfo: VersionInfo
2424
notFound: boolean
2525
buildingIndicator: boolean
26+
renderingIndicator: boolean
2627
staticIndicator: boolean
2728
showIndicator: boolean
2829
disableDevIndicator: boolean
@@ -47,6 +48,8 @@ export const ACTION_ERROR_OVERLAY_CLOSE = 'error-overlay-close'
4748
export const ACTION_ERROR_OVERLAY_TOGGLE = 'error-overlay-toggle'
4849
export const ACTION_BUILDING_INDICATOR_SHOW = 'building-indicator-show'
4950
export const ACTION_BUILDING_INDICATOR_HIDE = 'building-indicator-hide'
51+
export const ACTION_RENDERING_INDICATOR_SHOW = 'rendering-indicator-show'
52+
export const ACTION_RENDERING_INDICATOR_HIDE = 'rendering-indicator-hide'
5053

5154
export const STORAGE_KEY_THEME = '__nextjs-dev-tools-theme'
5255
export const STORAGE_KEY_POSITION = '__nextjs-dev-tools-position'
@@ -112,6 +115,13 @@ export interface BuildingIndicatorHideAction {
112115
type: typeof ACTION_BUILDING_INDICATOR_HIDE
113116
}
114117

118+
export interface RenderingIndicatorShowAction {
119+
type: typeof ACTION_RENDERING_INDICATOR_SHOW
120+
}
121+
export interface RenderingIndicatorHideAction {
122+
type: typeof ACTION_RENDERING_INDICATOR_HIDE
123+
}
124+
115125
export type BusEvent =
116126
| BuildOkAction
117127
| BuildErrorAction
@@ -128,6 +138,8 @@ export type BusEvent =
128138
| ErrorOverlayToggleAction
129139
| BuildingIndicatorShowAction
130140
| BuildingIndicatorHideAction
141+
| RenderingIndicatorShowAction
142+
| RenderingIndicatorHideAction
131143

132144
const REACT_ERROR_STACK_BOTTOM_FRAME_REGEX =
133145
// 1st group: v8
@@ -153,6 +165,7 @@ export const INITIAL_OVERLAY_STATE: Omit<
153165
buildError: null,
154166
errors: [],
155167
notFound: false,
168+
renderingIndicator: false,
156169
staticIndicator: false,
157170
/*
158171
This is set to `true` when we can reliably know

packages/next/src/client/components/react-dev-overlay/ui/components/errors/dev-tools-indicator/dev-tools-indicator.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const state: OverlayState = {
5555
versionInfo: mockVersionInfo,
5656
notFound: false,
5757
buildingIndicator: false,
58+
renderingIndicator: false,
5859
staticIndicator: true,
5960
debugInfo: { devtoolsFrontendUrl: undefined },
6061
isErrorOverlayOpen: false,

packages/next/src/client/components/react-dev-overlay/ui/components/errors/dev-tools-indicator/dev-tools-indicator.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
import { useState, useEffect, useRef, createContext, useContext } from 'react'
1111
import { Toast } from '../../toast'
1212
import { NextLogo } from './next-logo'
13-
import { useIsDevRendering } from '../../../../utils/dev-indicator/dev-render-indicator'
1413
import { useDelayedRender } from '../../../hooks/use-delayed-render'
1514
import { TurbopackInfo } from './dev-tools-info/turbopack-info'
1615
import { RouteInfo } from './dev-tools-info/route-info'
@@ -54,6 +53,7 @@ export function DevToolsIndicator({
5453
semver={state.versionInfo.installed}
5554
issueCount={errorCount}
5655
isDevBuilding={state.buildingIndicator}
56+
isDevRendering={state.renderingIndicator}
5757
isStaticRoute={state.staticIndicator}
5858
hide={() => {
5959
setIsDevToolsIndicatorVisible(false)
@@ -96,6 +96,7 @@ function DevToolsPopover({
9696
disabled,
9797
issueCount,
9898
isDevBuilding,
99+
isDevRendering,
99100
isStaticRoute,
100101
isTurbopack,
101102
isBuildError,
@@ -110,6 +111,7 @@ function DevToolsPopover({
110111
isStaticRoute: boolean
111112
semver: string | undefined
112113
isDevBuilding: boolean
114+
isDevRendering: boolean
113115
isTurbopack: boolean
114116
isBuildError: boolean
115117
hide: () => void
@@ -297,7 +299,7 @@ function DevToolsPopover({
297299
onTriggerClick={onTriggerClick}
298300
toggleErrorOverlay={toggleErrorOverlay}
299301
isDevBuilding={isDevBuilding}
300-
isDevRendering={useIsDevRendering()}
302+
isDevRendering={isDevRendering}
301303
isBuildError={isBuildError}
302304
scale={scale}
303305
/>

packages/next/src/client/components/react-dev-overlay/ui/dev-overlay.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const initialState: OverlayState = {
7474
refreshState: { type: 'idle' },
7575
notFound: false,
7676
buildingIndicator: false,
77+
renderingIndicator: false,
7778
staticIndicator: false,
7879
debugInfo: { devtoolsFrontendUrl: undefined },
7980
versionInfo: {

packages/next/src/client/components/react-dev-overlay/utils/dev-indicator/dev-render-indicator.tsx

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { useContext, useEffect, useTransition } from 'react'
2+
import { AppDevOverlayDispatchContext } from '../../app/app-dev-overlay'
3+
import {
4+
ACTION_RENDERING_INDICATOR_HIDE,
5+
ACTION_RENDERING_INDICATOR_SHOW,
6+
} from '../../shared'
7+
8+
export const useAppDevRenderingIndicator = () => {
9+
const dispatch = useContext(AppDevOverlayDispatchContext)
10+
const [isPending, startTransition] = useTransition()
11+
12+
useEffect(() => {
13+
// Only supported in App Router
14+
if (dispatch !== null) {
15+
if (isPending) {
16+
dispatch({ type: ACTION_RENDERING_INDICATOR_SHOW })
17+
} else {
18+
dispatch({ type: ACTION_RENDERING_INDICATOR_HIDE })
19+
}
20+
}
21+
}, [dispatch, isPending])
22+
23+
return startTransition
24+
}

packages/next/src/client/components/react-dev-overlay/utils/dev-indicator/use-sync-dev-render-indicator.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/next/src/client/components/use-action-queue.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@ export function useActionQueue(
3535
// this is conceptually how we're modeling the app router state, despite the
3636
// weird implementation details.
3737
if (process.env.NODE_ENV !== 'production') {
38-
const useSyncDevRenderIndicator =
39-
require('./react-dev-overlay/utils/dev-indicator/use-sync-dev-render-indicator')
40-
.useSyncDevRenderIndicator as typeof import('./react-dev-overlay/utils/dev-indicator/use-sync-dev-render-indicator').useSyncDevRenderIndicator
38+
const { useAppDevRenderingIndicator } =
39+
require('./react-dev-overlay/utils/dev-indicator/use-app-dev-rendering-indicator') as typeof import('./react-dev-overlay/utils/dev-indicator/use-app-dev-rendering-indicator')
4140
// eslint-disable-next-line react-hooks/rules-of-hooks
42-
const syncDevRenderIndicator = useSyncDevRenderIndicator()
41+
const appDevRenderingIndicator = useAppDevRenderingIndicator()
4342

4443
dispatch = (action: ReducerActions) => {
45-
syncDevRenderIndicator(() => {
44+
appDevRenderingIndicator(() => {
4645
actionQueue.dispatch(action, setState)
4746
})
4847
}

0 commit comments

Comments
 (0)