Unverified Commit c2085df2 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[dev-overlay] change dev indicator position by next config option (#76077)

### What?

This PR uses the `devIndicators.position` option to set the position of the dev indicator.
The default option is changed from `"bottom-right"` to `"bottom-left"` to sync the previous dev indicator behavior, but have covered backward compatibility for the default position of old overlay's build activity indicator.

### Success Criteria

- [x] Does setting `buildActivityPosition` correctly set the dev indicator position?
- [x] Does setting the `position` correctly set the dev indicator position?
- [x] Does it default to `"bottom-left"`?
- [x] Does the dev indicator popover display properly based on the `position`?

Backwards Compatible:

> Are there any breaking changes?

- [x]  Is the position `"bottom-right"` on the old overlay if the user hasn't set the `position`?
- [x] Is the position `"bottom-right"` on the old overlay if the user hasn't set the `buildActivityPosition`?
- [x] Does the position follow the `position` option?
- [x] Does the position follow the `buildActivityPosition` option?

https://github.com/user-attachments/assets/a5dba705-1b9d-4470-80e6-1952b22c2f46

Closes NDX-838
parent 698220d1
...@@ -239,8 +239,8 @@ export function getDefineEnv({ ...@@ -239,8 +239,8 @@ export function getDefineEnv({
'process.env.__NEXT_TRAILING_SLASH': config.trailingSlash, 'process.env.__NEXT_TRAILING_SLASH': config.trailingSlash,
'process.env.__NEXT_BUILD_INDICATOR': 'process.env.__NEXT_BUILD_INDICATOR':
config.devIndicators.buildActivity ?? true, config.devIndicators.buildActivity ?? true,
'process.env.__NEXT_BUILD_INDICATOR_POSITION': 'process.env.__NEXT_DEV_INDICATOR_POSITION':
config.devIndicators.position ?? 'bottom-right', config.devIndicators.position ?? 'bottom-left',
'process.env.__NEXT_STRICT_MODE': 'process.env.__NEXT_STRICT_MODE':
config.reactStrictMode === null ? false : config.reactStrictMode, config.reactStrictMode === null ? false : config.reactStrictMode,
'process.env.__NEXT_STRICT_MODE_APP': 'process.env.__NEXT_STRICT_MODE_APP':
......
...@@ -9,6 +9,13 @@ const meta: Meta<typeof DevToolsIndicator> = { ...@@ -9,6 +9,13 @@ const meta: Meta<typeof DevToolsIndicator> = {
parameters: { parameters: {
layout: 'centered', layout: 'centered',
}, },
argTypes: {
position: {
control: 'select',
options: ['top-left', 'top-right', 'bottom-left', 'bottom-right'],
defaultValue: 'bottom-left',
},
},
decorators: [ decorators: [
withShadowPortal, withShadowPortal,
// Test for high z-index // Test for high z-index
......
...@@ -7,17 +7,28 @@ import { Cross, NextLogo } from './internal/next-logo' ...@@ -7,17 +7,28 @@ import { Cross, NextLogo } from './internal/next-logo'
import { useIsDevBuilding } from '../../../../../../../dev/dev-build-indicator/internal/initialize-for-new-overlay' import { useIsDevBuilding } from '../../../../../../../dev/dev-build-indicator/internal/initialize-for-new-overlay'
import { useIsDevRendering } from './internal/dev-render-indicator' import { useIsDevRendering } from './internal/dev-render-indicator'
import { useDelayedRender } from '../../../hooks/use-delayed-render' import { useDelayedRender } from '../../../hooks/use-delayed-render'
import { noop as css } from '../../../helpers/noop-template'
// TODO: add E2E tests to cover different scenarios // TODO: add E2E tests to cover different scenarios
const INDICATOR_POSITION =
(process.env
.__NEXT_DEV_INDICATOR_POSITION as typeof window.__NEXT_DEV_INDICATOR_POSITION) ||
'bottom-left'
type DevToolsIndicatorPosition = typeof INDICATOR_POSITION
export function DevToolsIndicator({ export function DevToolsIndicator({
state, state,
errorCount, errorCount,
setIsErrorOverlayOpen, setIsErrorOverlayOpen,
position = INDICATOR_POSITION,
}: { }: {
state: OverlayState state: OverlayState
errorCount: number errorCount: number
setIsErrorOverlayOpen: Dispatch<SetStateAction<boolean>> setIsErrorOverlayOpen: Dispatch<SetStateAction<boolean>>
// Technically this prop isn't needed, but useful for testing.
position?: DevToolsIndicatorPosition
}) { }) {
const [isDevToolsIndicatorOpen, setIsDevToolsIndicatorOpen] = useState(true) const [isDevToolsIndicatorOpen, setIsDevToolsIndicatorOpen] = useState(true)
...@@ -32,6 +43,7 @@ export function DevToolsIndicator({ ...@@ -32,6 +43,7 @@ export function DevToolsIndicator({
}} }}
setIsErrorOverlayOpen={setIsErrorOverlayOpen} setIsErrorOverlayOpen={setIsErrorOverlayOpen}
isTurbopack={!!process.env.TURBOPACK} isTurbopack={!!process.env.TURBOPACK}
position={position}
/> />
) )
) )
...@@ -54,6 +66,7 @@ function DevToolsPopover({ ...@@ -54,6 +66,7 @@ function DevToolsPopover({
issueCount, issueCount,
isStaticRoute, isStaticRoute,
isTurbopack, isTurbopack,
position,
hide, hide,
setIsErrorOverlayOpen, setIsErrorOverlayOpen,
}: { }: {
...@@ -61,6 +74,7 @@ function DevToolsPopover({ ...@@ -61,6 +74,7 @@ function DevToolsPopover({
isStaticRoute: boolean isStaticRoute: boolean
semver: string | undefined semver: string | undefined
isTurbopack: boolean isTurbopack: boolean
position: DevToolsIndicatorPosition
hide: () => void hide: () => void
setIsErrorOverlayOpen: Dispatch<SetStateAction<boolean>> setIsErrorOverlayOpen: Dispatch<SetStateAction<boolean>>
}) { }) {
...@@ -174,12 +188,19 @@ function DevToolsPopover({ ...@@ -174,12 +188,19 @@ function DevToolsPopover({
}, ANIMATE_OUT_DURATION_MS) }, ANIMATE_OUT_DURATION_MS)
} }
const [vertical, horizontal] = position.split('-', 2)
return ( return (
<Toast <Toast
data-nextjs-toast data-nextjs-toast
style={{ style={{
boxShadow: 'none', boxShadow: 'none',
zIndex: 2147483647, zIndex: 2147483647,
// Reset the toast component's default positions.
bottom: 'initial',
left: 'initial',
[vertical]: 'var(--size-2_5)',
[horizontal]: 'var(--size-5)',
}} }}
> >
<NextLogo <NextLogo
...@@ -206,13 +227,15 @@ function DevToolsPopover({ ...@@ -206,13 +227,15 @@ function DevToolsPopover({
aria-orientation="vertical" aria-orientation="vertical"
aria-label="Next.js Dev Tools Items" aria-label="Next.js Dev Tools Items"
tabIndex={-1} tabIndex={-1}
className="menu" className="dev-tools-indicator-menu"
onKeyDown={onMenuKeydown} onKeyDown={onMenuKeydown}
data-rendered={rendered} data-rendered={rendered}
style={ style={
{ {
'--animate-out-duration-ms': `${ANIMATE_OUT_DURATION_MS}ms`, '--animate-out-duration-ms': `${ANIMATE_OUT_DURATION_MS}ms`,
'--animate-out-timing-function': ANIMATE_OUT_TIMING_FUNCTION, '--animate-out-timing-function': ANIMATE_OUT_TIMING_FUNCTION,
[vertical]: 'calc(100% + var(--size-gap))',
[horizontal]: 0,
} as React.CSSProperties } as React.CSSProperties
} }
> >
...@@ -223,7 +246,7 @@ function DevToolsPopover({ ...@@ -223,7 +246,7 @@ function DevToolsPopover({
setSelectedIndex, setSelectedIndex,
}} }}
> >
<div className="inner"> <div className="dev-tools-indicator-inner">
{issueCount > 0 && ( {issueCount > 0 && (
<MenuItem <MenuItem
index={0} index={0}
...@@ -249,7 +272,7 @@ function DevToolsPopover({ ...@@ -249,7 +272,7 @@ function DevToolsPopover({
)} )}
</div> </div>
<div className="footer"> <div className="dev-tools-indicator-footer">
<MenuItem <MenuItem
data-hide-dev-tools data-hide-dev-tools
label="Hide Dev Tools" label="Hide Dev Tools"
...@@ -296,7 +319,7 @@ function MenuItem({ ...@@ -296,7 +319,7 @@ function MenuItem({
return ( return (
<div <div
className="item" className="dev-tools-indicator-item"
data-index={index} data-index={index}
data-selected={selected} data-selected={selected}
onClick={click} onClick={click}
...@@ -317,16 +340,19 @@ function MenuItem({ ...@@ -317,16 +340,19 @@ function MenuItem({
tabIndex={selected ? 0 : -1} tabIndex={selected ? 0 : -1}
{...props} {...props}
> >
<span className="label">{label}</span> <span className="dev-tools-indicator-label">{label}</span>
<span className="value">{value}</span> <span className="dev-tools-indicator-value">{value}</span>
</div> </div>
) )
} }
function IssueCount({ children }: { children: number }) { function IssueCount({ children }: { children: number }) {
return ( return (
<span className="issueCount" data-has-issues={children > 0}> <span
<span className="indicator" /> className="dev-tools-indicator-issue-count"
data-has-issues={children > 0}
>
<span className="dev-tools-indicator-issue-count-indicator" />
{children} {children}
</span> </span>
) )
...@@ -431,3 +457,131 @@ function ExternalIcon() { ...@@ -431,3 +457,131 @@ function ExternalIcon() {
</svg> </svg>
) )
} }
export const DEV_TOOLS_INDICATOR_STYLES = css`
.dev-tools-indicator-menu {
-webkit-font-smoothing: antialiased;
display: flex;
flex-direction: column;
align-items: flex-start;
background: var(--color-background-100);
border: 1px solid var(--color-gray-alpha-400);
background-clip: padding-box;
box-shadow: var(--shadow-menu);
border-radius: var(--rounded-xl);
position: absolute;
font-family: var(--font-stack-sans);
z-index: 1000;
overflow: hidden;
opacity: 0;
outline: 0;
min-width: 248px;
transition: opacity var(--animate-out-duration-ms)
var(--animate-out-timing-function);
&[data-rendered='true'] {
opacity: 1;
scale: 1;
}
}
.dev-tools-indicator-inner {
padding: 6px;
width: 100%;
}
.dev-tools-indicator-item {
display: flex;
align-items: center;
padding: 8px 6px;
height: 36px;
border-radius: 6px;
text-decoration: none !important;
user-select: none;
&:focus-visible {
outline: 0;
}
}
.dev-tools-indicator-footer {
background: var(--color-background-200);
padding: 6px;
border-top: 1px solid var(--color-gray-400);
width: 100%;
}
.dev-tools-indicator-item[data-selected='true'] {
cursor: pointer;
background-color: var(--color-gray-200);
}
.dev-tools-indicator-label {
font-size: var(--size-font-small);
line-height: var(--size-5);
color: var(--color-gray-1000);
}
.dev-tools-indicator-value {
font-size: var(--size-font-small);
line-height: var(--size-5);
color: var(--color-gray-900);
margin-left: auto;
}
.dev-tools-indicator-issue-count {
--color-primary: var(--color-gray-800);
--color-secondary: var(--color-gray-100);
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
gap: 8px;
min-width: 41px;
height: 24px;
background: var(--color-background-100);
border: 1px solid var(--color-gray-alpha-400);
background-clip: padding-box;
box-shadow: var(--shadow-small);
padding: 2px;
color: var(--color-gray-1000);
border-radius: 128px;
font-weight: 500;
font-size: 13px;
font-variant-numeric: tabular-nums;
&[data-has-issues='true'] {
--color-primary: var(--color-red-800);
--color-secondary: var(--color-red-100);
}
.dev-tools-indicator-issue-count-indicator {
width: 8px;
height: 8px;
background: var(--color-primary);
box-shadow: 0 0 0 2px var(--color-secondary);
border-radius: 50%;
}
}
.dev-tools-indicator-shortcut {
display: flex;
gap: var(--size-1);
kbd {
width: var(--size-5);
height: var(--size-5);
display: flex;
justify-content: center;
align-items: center;
border-radius: var(--rounded-md);
border: 1px solid var(--color-gray-400);
font-family: var(--font-stack-sans);
background: var(--color-background-100);
color: var(--color-gray-1000);
text-align: center;
font-size: var(--size-font-smaller);
line-height: var(--size-4);
}
}
`
import { noop as css } from '../../../helpers/noop-template'
export const styles = css`
.menu {
-webkit-font-smoothing: antialiased;
display: flex;
flex-direction: column;
align-items: flex-start;
background: var(--color-background-100);
border: 1px solid var(--color-gray-alpha-400);
background-clip: padding-box;
box-shadow: var(--shadow-menu);
border-radius: var(--rounded-xl);
position: absolute;
font-family: var(--font-stack-sans);
bottom: calc(100% + var(--size-gap));
left: 0;
z-index: 1000;
overflow: hidden;
opacity: 0;
outline: 0;
min-width: 248px;
transition: opacity var(--animate-out-duration-ms)
var(--animate-out-timing-function);
&[data-rendered='true'] {
opacity: 1;
scale: 1;
}
}
.inner {
padding: 6px;
width: 100%;
}
.item {
display: flex;
align-items: center;
padding: 8px 6px;
height: 36px;
border-radius: 6px;
text-decoration: none !important;
user-select: none;
&:focus-visible {
outline: 0;
}
}
.footer {
background: var(--color-background-200);
padding: 6px;
border-top: 1px solid var(--color-gray-400);
width: 100%;
}
.item[data-selected='true'] {
cursor: pointer;
background-color: var(--color-gray-200);
}
.label {
font-size: var(--size-font-small);
line-height: var(--size-5);
color: var(--color-gray-1000);
}
.value {
font-size: var(--size-font-small);
line-height: var(--size-5);
color: var(--color-gray-900);
margin-left: auto;
}
.issueCount {
--color-primary: var(--color-gray-800);
--color-secondary: var(--color-gray-100);
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
gap: 8px;
min-width: 41px;
height: 24px;
background: var(--color-background-100);
border: 1px solid var(--color-gray-alpha-400);
background-clip: padding-box;
box-shadow: var(--shadow-small);
padding: 2px;
color: var(--color-gray-1000);
border-radius: 128px;
font-weight: 500;
font-size: 13px;
font-variant-numeric: tabular-nums;
&[data-has-issues='true'] {
--color-primary: var(--color-red-800);
--color-secondary: var(--color-red-100);
}
.indicator {
width: 8px;
height: 8px;
background: var(--color-primary);
box-shadow: 0 0 0 2px var(--color-secondary);
border-radius: 50%;
}
}
.shortcut {
display: flex;
gap: var(--size-1);
kbd {
width: var(--size-5);
height: var(--size-5);
display: flex;
justify-content: center;
align-items: center;
border-radius: var(--rounded-md);
border: 1px solid var(--color-gray-400);
font-family: var(--font-stack-sans);
background: var(--color-background-100);
color: var(--color-gray-1000);
text-align: center;
font-size: var(--size-font-smaller);
line-height: var(--size-4);
}
}
`
...@@ -13,7 +13,7 @@ import { styles as containerErrorStyles } from '../container/errors' ...@@ -13,7 +13,7 @@ import { styles as containerErrorStyles } from '../container/errors'
import { styles as containerRuntimeErrorStyles } from '../container/runtime-error' import { styles as containerRuntimeErrorStyles } from '../container/runtime-error'
import { COPY_BUTTON_STYLES } from '../components/copy-button' import { COPY_BUTTON_STYLES } from '../components/copy-button'
import { CALL_STACK_FRAME_STYLES } from '../components/call-stack-frame/call-stack-frame' import { CALL_STACK_FRAME_STYLES } from '../components/call-stack-frame/call-stack-frame'
import { styles as devToolsIndicator } from '../components/errors/dev-tools-indicator/styles' import { DEV_TOOLS_INDICATOR_STYLES } from '../components/errors/dev-tools-indicator/dev-tools-indicator'
import { noop as css } from '../helpers/noop-template' import { noop as css } from '../helpers/noop-template'
import { EDITOR_LINK_STYLES } from '../components/terminal/editor-link' import { EDITOR_LINK_STYLES } from '../components/terminal/editor-link'
import { ENVIRONMENT_NAME_LABEL_STYLES } from '../components/errors/environment-name-label/environment-name-label' import { ENVIRONMENT_NAME_LABEL_STYLES } from '../components/errors/environment-name-label/environment-name-label'
...@@ -38,7 +38,7 @@ export function ComponentStyles() { ...@@ -38,7 +38,7 @@ export function ComponentStyles() {
${containerErrorStyles} ${containerErrorStyles}
${containerRuntimeErrorStyles} ${containerRuntimeErrorStyles}
${versionStaleness} ${versionStaleness}
${devToolsIndicator} ${DEV_TOOLS_INDICATOR_STYLES}
`} `}
</style> </style>
) )
......
...@@ -6,5 +6,5 @@ export const initializeDevBuildIndicatorForAppRouter = () => { ...@@ -6,5 +6,5 @@ export const initializeDevBuildIndicatorForAppRouter = () => {
return return
} }
devBuildIndicator.initialize(process.env.__NEXT_BUILD_INDICATOR_POSITION) devBuildIndicator.initialize(process.env.__NEXT_DEV_INDICATOR_POSITION)
} }
...@@ -8,7 +8,7 @@ export const initializeDevBuildIndicatorForPageRouter = () => { ...@@ -8,7 +8,7 @@ export const initializeDevBuildIndicatorForPageRouter = () => {
return return
} }
devBuildIndicator.initialize(process.env.__NEXT_BUILD_INDICATOR_POSITION) devBuildIndicator.initialize(process.env.__NEXT_DEV_INDICATOR_POSITION)
// Add message listener specifically for Pages Router to handle lifecycle events // Add message listener specifically for Pages Router to handle lifecycle events
// related to dev builds (building, built, sync) // related to dev builds (building, built, sync)
......
...@@ -854,16 +854,16 @@ export interface NextConfig extends Record<string, any> { ...@@ -854,16 +854,16 @@ export interface NextConfig extends Record<string, any> {
* @deprecated Renamed as `position`. * @deprecated Renamed as `position`.
*/ */
buildActivityPosition?: buildActivityPosition?:
| 'bottom-right'
| 'bottom-left'
| 'top-right'
| 'top-left' | 'top-left'
| 'top-right'
| 'bottom-left'
| 'bottom-right'
/** /**
* Position of "building..." indicator in browser * Position of the development tools indicator in the browser window.
* @default "bottom-right" * @default "bottom-left"
* */ * */
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
} }
/** /**
...@@ -1109,7 +1109,7 @@ export const defaultConfig: NextConfig = { ...@@ -1109,7 +1109,7 @@ export const defaultConfig: NextConfig = {
compress: true, compress: true,
images: imageConfigDefault, images: imageConfigDefault,
devIndicators: { devIndicators: {
position: 'bottom-right', position: 'bottom-left',
}, },
onDemandEntries: { onDemandEntries: {
maxInactiveAge: 60 * 1000, maxInactiveAge: 60 * 1000,
......
...@@ -965,6 +965,19 @@ function assignDefaults( ...@@ -965,6 +965,19 @@ function assignDefaults(
appIsrStatus: result.devIndicators?.appIsrStatus ?? true, appIsrStatus: result.devIndicators?.appIsrStatus ?? true,
buildActivity: result.devIndicators?.buildActivity ?? true, buildActivity: result.devIndicators?.buildActivity ?? true,
} }
// If the user didn't explicitly set `position` or `buildActivityPosition` option,
// the default is going to be "bottom-left". However, the default position for the
// old build activity indicator was "bottom-right" which becomes a breaking change.
// Therefore, set to "bottom-right" if the user didn't explicitly set the option.
if (!hasWarnedBuildActivityPosition) {
result.devIndicators = {
...result.devIndicators,
position: userConfig.devIndicators?.position
? result.devIndicators.position
: 'bottom-right',
}
}
} }
result.experimental.optimizePackageImports = [ result.experimental.optimizePackageImports = [
......
...@@ -48,6 +48,12 @@ interface Window { ...@@ -48,6 +48,12 @@ interface Window {
__NEXT_HMR_CB?: null | ((message?: string) => void) __NEXT_HMR_CB?: null | ((message?: string) => void)
/** @internal */ /** @internal */
__next_root_layout_missing_tags?: ('html' | 'body')[] __next_root_layout_missing_tags?: ('html' | 'body')[]
/** @internal */
__NEXT_DEV_INDICATOR_POSITION?:
| 'top-left'
| 'top-right'
| 'bottom-left'
| 'bottom-right'
} }
interface NextFetchRequestConfig { interface NextFetchRequestConfig {
......
...@@ -7,7 +7,8 @@ export default function Page() { ...@@ -7,7 +7,8 @@ export default function Page() {
const { items, loadMoreItems } = useContext(ItemsContext) const { items, loadMoreItems } = useContext(ItemsContext)
return ( return (
<div> // Dev Indicator blocking the click.
<div style={{ paddingBottom: 60 }}>
<h1>Page</h1> <h1>Page</h1>
<ul> <ul>
{items.map((item) => ( {items.map((item) => (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment