Unverified Commit 025657cf authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

[dev-overlay]: hiding devtools shouldn't hide errors (#76399)

Currently when you select "Hide Dev Tools", if an error comes in you
won't see the error indicator anymore.

This follows the same treatment as when the indicator is disabled in
next config, which is to only show you errors, and not the regular
indicator/popover.
parent 0d4076ed
...@@ -36,24 +36,23 @@ export function DevToolsIndicator({ ...@@ -36,24 +36,23 @@ export function DevToolsIndicator({
// Technically this prop isn't needed, but useful for testing. // Technically this prop isn't needed, but useful for testing.
position?: DevToolsIndicatorPosition position?: DevToolsIndicatorPosition
}) { }) {
const [isDevToolsIndicatorOpen, setIsDevToolsIndicatorOpen] = useState(true) const [isDevToolsIndicatorVisible, setIsDevToolsIndicatorVisible] =
useState(true)
return ( return (
isDevToolsIndicatorOpen && ( <DevToolsPopover
<DevToolsPopover semver={state.versionInfo.installed}
semver={state.versionInfo.installed} issueCount={errorCount}
issueCount={errorCount} isStaticRoute={state.staticIndicator}
isStaticRoute={state.staticIndicator} hide={() => {
hide={() => { setIsDevToolsIndicatorVisible(false)
setIsDevToolsIndicatorOpen(false) }}
}} setIsErrorOverlayOpen={setIsErrorOverlayOpen}
setIsErrorOverlayOpen={setIsErrorOverlayOpen} isTurbopack={!!process.env.TURBOPACK}
isTurbopack={!!process.env.TURBOPACK} position={position}
position={position} disabled={state.disableDevIndicator || !isDevToolsIndicatorVisible}
disabled={state.disableDevIndicator} isBuildError={isBuildError}
isBuildError={isBuildError} />
/>
)
) )
} }
......
...@@ -2,7 +2,7 @@ import { createNext, FileRef } from 'e2e-utils' ...@@ -2,7 +2,7 @@ import { createNext, FileRef } from 'e2e-utils'
import webdriver, { BrowserInterface } from 'next-webdriver' import webdriver, { BrowserInterface } from 'next-webdriver'
import { NextInstance } from 'e2e-utils' import { NextInstance } from 'e2e-utils'
import { join } from 'path' import { join } from 'path'
import { check } from 'next-test-utils' import { retry } from 'next-test-utils'
describe('client-dev-overlay', () => { describe('client-dev-overlay', () => {
let next: NextInstance let next: NextInstance
...@@ -30,6 +30,7 @@ describe('client-dev-overlay', () => { ...@@ -30,6 +30,7 @@ describe('client-dev-overlay', () => {
fullScreenDialog: '[data-nextjs-dialog]', fullScreenDialog: '[data-nextjs-dialog]',
toast: '[data-nextjs-toast]', toast: '[data-nextjs-toast]',
popover: '[data-nextjs-dev-tools-button]', popover: '[data-nextjs-dev-tools-button]',
indicator: '[data-next-badge-root]',
minimizeButton: 'body', minimizeButton: 'body',
hideButton: '[data-hide-dev-tools]', hideButton: '[data-hide-dev-tools]',
} }
...@@ -50,13 +51,11 @@ describe('client-dev-overlay', () => { ...@@ -50,13 +51,11 @@ describe('client-dev-overlay', () => {
await getMinimizeButton().click() await getMinimizeButton().click()
await getToast().click() await getToast().click()
await check(async () => { await retry(async () => {
return (await elementExistsInNextJSPortalShadowDOM( expect(
selectors.fullScreenDialog await elementExistsInNextJSPortalShadowDOM(selectors.fullScreenDialog)
)) ).toBe(true)
? 'success' })
: 'missing'
}, 'success')
}) })
it('should be able to minimize the fullscreen overlay', async () => { it('should be able to minimize the fullscreen overlay', async () => {
...@@ -66,22 +65,46 @@ describe('client-dev-overlay', () => { ...@@ -66,22 +65,46 @@ describe('client-dev-overlay', () => {
) )
}) })
it('should be able to hide the minimized overlay', async () => { it('should keep the error indicator visible when there are errors', async () => {
await getMinimizeButton().click() await getMinimizeButton().click()
await getPopover().click() await getPopover().click()
await getHideButton().click() await getHideButton().click()
await check(async () => { await retry(async () => {
const exists = await elementExistsInNextJSPortalShadowDOM(selectors.toast) const display = await browser.eval(
return exists ? 'found' : 'success' `getComputedStyle(document.querySelector('nextjs-portal').shadowRoot.querySelector('${selectors.indicator}')).display`
}, 'success') )
expect(display).toBe('block')
})
})
it('should be possible to hide the minimized overlay when there are no errors', async () => {
const originalContent = await next.readFile('pages/index.js')
try {
await next.patchFile('pages/index.js', (content) => {
return content.replace(`throw Error('example runtime error')`, '')
})
await getMinimizeButton().click()
await getPopover().click()
await getHideButton().click()
await retry(async () => {
const display = await browser.eval(
`getComputedStyle(document.querySelector('nextjs-portal').shadowRoot.querySelector('${selectors.indicator}')).display`
)
expect(display).toBe('none')
})
} finally {
await next.patchFile('pages/index.js', originalContent)
}
}) })
it('should have a role of "dialog" if the page is focused', async () => { it('should have a role of "dialog" if the page is focused', async () => {
await check(async () => { await retry(async () => {
return (await elementExistsInNextJSPortalShadowDOM('[role="dialog"]')) expect(
? 'exists' await elementExistsInNextJSPortalShadowDOM('[role="dialog"]')
: 'missing' ).toBe(true)
}, 'exists') })
}) })
}) })
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