Unverified Commit 0a298885 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[backport] fix: devtools initial position should be from next config (#83571) (#83994)

backports #83571
parent 7a53950c
......@@ -251,6 +251,9 @@ function getStackIgnoringStrictMode(stack: string | undefined) {
const shouldDisableDevIndicator =
process.env.__NEXT_DEV_INDICATOR?.toString() === 'false'
const devToolsInitialPositionFromNextConfig = (process.env
.__NEXT_DEV_INDICATOR_POSITION ?? 'bottom-left') as Corners
export const INITIAL_OVERLAY_STATE: Omit<
OverlayState,
'isErrorOverlayOpen' | 'routerType'
......@@ -272,9 +275,9 @@ export const INITIAL_OVERLAY_STATE: Omit<
refreshState: { type: 'idle' },
versionInfo: { installed: '0.0.0', staleness: 'unknown' },
debugInfo: { devtoolsFrontendUrl: undefined },
devToolsPosition: 'bottom-left',
devToolsPosition: devToolsInitialPositionFromNextConfig,
devToolsPanelPosition: {
[STORE_KEY_SHARED_PANEL_LOCATION]: 'bottom-left',
[STORE_KEY_SHARED_PANEL_LOCATION]: devToolsInitialPositionFromNextConfig,
},
devToolsPanelSize: {},
scale: NEXT_DEV_TOOLS_SCALE.Medium,
......
import type { ReactNode } from 'react'
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return <p>hello world</p>
}
import { nextTestSetup } from 'e2e-utils'
import { getDevIndicatorPosition } from './utils'
describe('devtools-position-bottom-left', () => {
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
devIndicators: {
position: 'bottom-left',
},
},
})
it('should devtools indicator position initially be bottom-left when configured', async () => {
const browser = await next.browser('/')
const style = await getDevIndicatorPosition(browser)
expect(style).toContain('bottom: 20px')
expect(style).toContain('left: 20px')
})
})
import { nextTestSetup } from 'e2e-utils'
import { getDevIndicatorPosition } from './utils'
describe('devtools-position-bottom-right', () => {
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
devIndicators: {
position: 'bottom-right',
},
},
})
it('should devtools indicator position initially be bottom-right when configured', async () => {
const browser = await next.browser('/')
const style = await getDevIndicatorPosition(browser)
expect(style).toContain('bottom: 20px')
expect(style).toContain('right: 20px')
})
})
import { nextTestSetup } from 'e2e-utils'
import { getDevIndicatorPosition } from './utils'
describe('devtools-position-default', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should devtools indicator position initially be bottom-left by default', async () => {
const browser = await next.browser('/')
const style = await getDevIndicatorPosition(browser)
expect(style).toContain('bottom: 20px')
expect(style).toContain('left: 20px')
})
})
import { nextTestSetup } from 'e2e-utils'
import { getDevIndicatorPosition } from './utils'
describe('devtools-position-persistence', () => {
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
devIndicators: {
position: 'top-right',
},
},
})
it('should maintain devtools indicator position after navigation', async () => {
const browser = await next.browser('/')
let style = await getDevIndicatorPosition(browser)
expect(style).toContain('top: 20px')
expect(style).toContain('right: 20px')
// Navigate and check devtools indicator position is maintained
await browser.refresh()
await browser.waitForIdleNetwork()
style = await getDevIndicatorPosition(browser)
expect(style).toContain('top: 20px')
expect(style).toContain('right: 20px')
})
})
import { nextTestSetup } from 'e2e-utils'
import { getDevIndicatorPosition } from './utils'
describe('devtools-position-top-left', () => {
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
devIndicators: {
position: 'top-left',
},
},
})
it('should devtools indicator position initially be top-left when configured', async () => {
const browser = await next.browser('/')
const style = await getDevIndicatorPosition(browser)
expect(style).toContain('top: 20px')
expect(style).toContain('left: 20px')
})
})
import { nextTestSetup } from 'e2e-utils'
import { getDevIndicatorPosition } from './utils'
describe('devtools-position-top-right', () => {
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
devIndicators: {
position: 'top-right',
},
},
})
it('should devtools indicator position initially be top-right when configured', async () => {
const browser = await next.browser('/')
const style = await getDevIndicatorPosition(browser)
expect(style).toContain('top: 20px')
expect(style).toContain('right: 20px')
})
})
import type { Playwright } from '../../../lib/next-webdriver'
import { assertHasDevToolsIndicator } from 'next-test-utils'
export async function getDevIndicatorPosition(browser: Playwright) {
// assert before eval() to prevent race condition
await assertHasDevToolsIndicator(browser)
const style = await browser.eval(() => {
return (
[].slice
.call(document.querySelectorAll('nextjs-portal'))
.find((p) => p.shadowRoot.querySelector('[data-nextjs-toast]'))
// portal
?.shadowRoot?.querySelector('[data-nextjs-toast]')
?.getAttribute('style') || ''
)
})
return style || ''
}
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