Skip to content

Commit e46bc8b

Browse files
committed
[devtools] port devtools scale to dispatcher
1 parent 7960359 commit e46bc8b

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

packages/next/src/next-devtools/dev-overlay/components/devtools-indicator/devtools-indicator.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { CSSProperties } from 'react'
22
import type { OverlayState, OverlayDispatch } from '../../shared'
3-
import type { DevToolsScale } from '../errors/dev-tools-indicator/dev-tools-info/preferences'
43

54
import { useState } from 'react'
65
import { NextLogo } from './next-logo'
@@ -26,13 +25,11 @@ export function DevToolsIndicator({
2625
dispatch,
2726
errorCount,
2827
isBuildError,
29-
scale,
3028
}: {
3129
state: OverlayState
3230
dispatch: OverlayDispatch
3331
errorCount: number
3432
isBuildError: boolean
35-
scale: DevToolsScale
3633
}) {
3734
const [open, setOpen] = useState(false)
3835

@@ -89,7 +86,7 @@ export function DevToolsIndicator({
8986
isDevBuilding={state.buildingIndicator}
9087
isDevRendering={state.renderingIndicator}
9188
isBuildError={isBuildError}
92-
scale={scale}
89+
scale={state.scale}
9390
/>
9491
</Draggable>
9592
</Toast>

packages/next/src/next-devtools/dev-overlay/dev-overlay.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export function DevOverlay({
4141
(process.env.__NEXT_DEVTOOL_NEW_PANEL_UI ? (
4242
<>
4343
<DevToolsIndicatorNew
44-
scale={scale}
4544
state={state}
4645
dispatch={dispatch}
4746
errorCount={totalErrorCount}

packages/next/src/next-devtools/dev-overlay/shared.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import { isConsoleError } from '../shared/console-error'
1010

1111
export type Corners = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
1212

13+
const BASE_SIZE = 16
14+
15+
export const NEXT_DEV_TOOLS_SCALE = {
16+
Small: BASE_SIZE / 14,
17+
Medium: BASE_SIZE / 16,
18+
Large: BASE_SIZE / 18,
19+
}
20+
1321
type FastRefreshState =
1422
/** No refresh in progress. */
1523
| { type: 'idle' }
@@ -33,6 +41,7 @@ export interface OverlayState {
3341
isErrorOverlayOpen: boolean
3442
isDevToolsPanelOpen: boolean
3543
indicatorPosition: Corners
44+
scale: number
3645
}
3746
export type OverlayDispatch = React.Dispatch<DispatcherEvent>
3847

@@ -61,6 +70,7 @@ export const ACTION_DEVTOOLS_PANEL_CLOSE = 'devtools-panel-close'
6170
export const ACTION_DEVTOOLS_PANEL_TOGGLE = 'devtools-panel-toggle'
6271

6372
export const ACTION_DEVTOOLS_INDICATOR_POSITION = 'devtools-indicator-position'
73+
export const ACTION_DEVTOOLS_SCALE = 'devtools-scale'
6474

6575
export const STORAGE_KEY_THEME = '__nextjs-dev-tools-theme'
6676
export const STORAGE_KEY_POSITION = '__nextjs-dev-tools-position'
@@ -150,6 +160,11 @@ export interface DevToolsIndicatorPositionAction {
150160
indicatorPosition: Corners
151161
}
152162

163+
export interface DevToolsScaleAction {
164+
type: typeof ACTION_DEVTOOLS_SCALE
165+
scale: number
166+
}
167+
153168
export type DispatcherEvent =
154169
| BuildOkAction
155170
| BuildErrorAction
@@ -172,6 +187,7 @@ export type DispatcherEvent =
172187
| DevToolsPanelCloseAction
173188
| DevToolsPanelToggleAction
174189
| DevToolsIndicatorPositionAction
190+
| DevToolsScaleAction
175191

176192
const REACT_ERROR_STACK_BOTTOM_FRAME_REGEX =
177193
// 1st group: v8
@@ -212,8 +228,12 @@ export const INITIAL_OVERLAY_STATE: Omit<
212228
debugInfo: { devtoolsFrontendUrl: undefined },
213229
isDevToolsPanelOpen: false,
214230
indicatorPosition:
215-
(localStorage.getItem(STORAGE_KEY_POSITION) as DevToolsIndicatorPosition) ??
231+
(localStorage.getItem(STORAGE_KEY_POSITION) as Corners) ??
216232
'bottom-left',
233+
scale:
234+
localStorage.getItem(STORAGE_KEY_SCALE)
235+
? Number(localStorage.getItem(STORAGE_KEY_SCALE))
236+
: NEXT_DEV_TOOLS_SCALE.Medium,
217237
}
218238

219239
function getInitialState(
@@ -388,6 +408,9 @@ export function useErrorOverlayReducer(
388408
case ACTION_DEVTOOLS_INDICATOR_POSITION: {
389409
return { ...state, indicatorPosition: action.indicatorPosition }
390410
}
411+
case ACTION_DEVTOOLS_SCALE: {
412+
return { ...state, scale: action.scale }
413+
}
391414
default: {
392415
return state
393416
}

0 commit comments

Comments
 (0)