Unverified Commit 23f45926 authored by Aurora Scharff's avatar Aurora Scharff Committed by GitHub

Show compiling status alongside DevTools issues (#100178)

parent b087b286
...@@ -114,6 +114,9 @@ export function NextLogo({ ...@@ -114,6 +114,9 @@ export function NextLogo({
state.cacheIndicator state.cacheIndicator
) )
const showStatusIndicator = displayStatus !== Status.None const showStatusIndicator = displayStatus !== Status.None
const statusReplacesIssues = showStatusIndicator && !state.disableDevIndicator
const showIssues =
!statusReplacesIssues && (isErrorExpanded || state.disableDevIndicator)
const ref = useRef<HTMLDivElement | null>(null) const ref = useRef<HTMLDivElement | null>(null)
const measuredWidth = useMeasureWidth(ref) const measuredWidth = useMeasureWidth(ref)
...@@ -438,9 +441,9 @@ export function NextLogo({ ...@@ -438,9 +441,9 @@ export function NextLogo({
<div <div
data-next-badge data-next-badge
data-error={hasError && !insightsOnly} data-error={hasError && !insightsOnly}
data-insights-only={insightsOnly} data-insights-only={insightsOnly && !statusReplacesIssues}
data-error-expanded={isExpanded} data-error-expanded={isExpanded}
data-status={hasError ? Status.None : displayStatus} data-status={displayStatus}
data-cache-badge={cacheBadge ?? undefined} data-cache-badge={cacheBadge ?? undefined}
data-animate={newErrorDetected} data-animate={newErrorDetected}
style={{ width }} style={{ width }}
...@@ -460,7 +463,7 @@ export function NextLogo({ ...@@ -460,7 +463,7 @@ export function NextLogo({
aria-label={`${isMenuOpen ? 'Close' : 'Open'} Next.js Dev Tools`} aria-label={`${isMenuOpen ? 'Close' : 'Open'} Next.js Dev Tools`}
data-nextjs-dev-tools-button data-nextjs-dev-tools-button
style={{ style={{
display: showStatusIndicator && !hasError ? 'none' : 'flex', display: showStatusIndicator ? 'none' : 'flex',
}} }}
{...buttonProps} {...buttonProps}
> >
...@@ -470,7 +473,7 @@ export function NextLogo({ ...@@ -470,7 +473,7 @@ export function NextLogo({
{isExpanded && ( {isExpanded && (
<> <>
{/* Error badge has priority over cache indicator */} {/* Error badge has priority over cache indicator */}
{(isErrorExpanded || state.disableDevIndicator) && ( {showIssues && (
<div data-issues data-toast-pill> <div data-issues data-toast-pill>
<button <button
data-issues-open data-issues-open
...@@ -542,14 +545,13 @@ export function NextLogo({ ...@@ -542,14 +545,13 @@ export function NextLogo({
/> />
)} )}
{/* Status indicator shown while rendering or compiling */} {/* Status indicator shown while rendering or compiling */}
{showStatusIndicator && {showStatusIndicator && !state.disableDevIndicator && (
!hasError && <StatusIndicator
!state.disableDevIndicator && ( status={displayStatus}
<StatusIndicator isError={hasError && !insightsOnly}
status={displayStatus} onClick={onTriggerClick}
onClick={onTriggerClick} />
/> )}
)}
</> </>
)} )}
</div> </div>
......
...@@ -35,10 +35,15 @@ export function getCurrentStatus( ...@@ -35,10 +35,15 @@ export function getCurrentStatus(
interface StatusIndicatorProps { interface StatusIndicatorProps {
status: Status status: Status
isError?: boolean
onClick?: () => void onClick?: () => void
} }
export function StatusIndicator({ status, onClick }: StatusIndicatorProps) { export function StatusIndicator({
status,
isError = false,
onClick,
}: StatusIndicatorProps) {
const statusText: Record<Status, string> = { const statusText: Record<Status, string> = {
[Status.None]: '', [Status.None]: '',
[Status.Compiling]: 'Compiling', [Status.Compiling]: 'Compiling',
...@@ -170,7 +175,7 @@ export function StatusIndicator({ status, onClick }: StatusIndicatorProps) { ...@@ -170,7 +175,7 @@ export function StatusIndicator({ status, onClick }: StatusIndicatorProps) {
<div <div
data-status-dot data-status-dot
style={{ style={{
backgroundColor: statusDotColor[status], backgroundColor: isError ? '#fff' : statusDotColor[status],
}} }}
/> />
)} )}
......
import message from './message.disabled.slow'
export default function Page() {
return <p>{message}</p>
}
import message from './message.enabled.slow'
export default function Page() {
return <p>{message}</p>
}
'use client'
import { useEffect } from 'react'
import Link from 'next/link'
export default function Page() {
useEffect(() => {
console.error('test issue')
}, [])
return (
<>
<Link
id="to-enabled-slow"
href="/app/build-indicator/enabled-slow"
prefetch={false}
>
Go to enabled slow page
</Link>
<Link
id="to-disabled-slow"
href="/app/build-indicator/disabled-slow"
prefetch={false}
>
Go to disabled slow page
</Link>
</>
)
}
import { nextTestSetup } from 'e2e-utils'
import { retry, toggleDevToolsIndicatorPopover } from 'next-test-utils'
const installCheckCompilingReplacesIssue = (browser) => {
return browser.eval(`(function() {
sessionStorage.setItem('showedCompilingInPlaceOfIssue', 'false')
window.checkInterval = setInterval(function() {
const root = document.querySelector('nextjs-portal').shadowRoot
const statusElement = root.querySelector('[data-indicator-status]')
const issuesElement = root.querySelector('[data-issues]')
const logoButton = root.querySelector('[data-nextjs-dev-tools-button]')
const badge = root.querySelector('[data-next-badge]')
const statusDot = root.querySelector('[data-status-dot]')
const isVisible =
statusElement?.textContent.includes('Compiling') &&
issuesElement === null &&
logoButton !== null &&
getComputedStyle(logoButton).display === 'none' &&
badge?.getAttribute('data-error') === 'true' &&
getComputedStyle(badge).backgroundColor === 'rgb(202, 42, 48)' &&
getComputedStyle(statusDot).backgroundColor === 'rgb(255, 255, 255)'
if (isVisible) {
sessionStorage.setItem('showedCompilingInPlaceOfIssue', 'true')
clearInterval(window.checkInterval)
}
}, 5)
})()`)
}
const installCheckCompilingKeepsDisabledIssue = (browser) => {
return browser.eval(`(function() {
sessionStorage.setItem('keptDisabledIssueWhileCompiling', 'false')
window.checkInterval = setInterval(function() {
const root = document.querySelector('nextjs-portal').shadowRoot
const statusElement = root.querySelector('[data-indicator-status]')
const issuesElement = root.querySelector('[data-issues]')
const badge = root.querySelector('[data-next-badge]')
const status = badge?.getAttribute('data-status')
const isVisible =
status &&
status !== 'none' &&
statusElement === null &&
issuesElement?.textContent.includes('Issue') &&
root.querySelector('[data-disabled-icon]') !== null &&
badge?.getAttribute('data-error') === 'true'
if (isVisible) {
sessionStorage.setItem('keptDisabledIssueWhileCompiling', 'true')
clearInterval(window.checkInterval)
}
}, 5)
})()`)
}
const waitForIssue = (browser) =>
retry(async () => {
expect(
await browser.eval(`(function() {
const root = document.querySelector('nextjs-portal').shadowRoot
return root.querySelector('[data-issues]')?.textContent ?? null
})()`)
).toContain('Issue')
})
describe('build indicator with an issue', () => {
const { next } = nextTestSetup({
files: __dirname,
env: {
__NEXT_DEV_INDICATOR_COOLDOWN_MS: '0',
},
})
it('shows red compiling status in place of an existing issue', async () => {
const browser = await next.browser('/app/build-indicator/issue')
await waitForIssue(browser)
await installCheckCompilingReplacesIssue(browser)
await browser.elementByCss('#to-enabled-slow').click()
await retry(async () => {
expect(
await browser.eval(
`sessionStorage.getItem('showedCompilingInPlaceOfIssue')`
)
).toBe('true')
})
await retry(async () => {
expect(await browser.elementByCss('main > p').text()).toBe(
'Enabled slow page'
)
})
})
it('keeps the disabled issue visible while compiling', async () => {
const browser = await next.browser('/app/build-indicator/issue')
await waitForIssue(browser)
await toggleDevToolsIndicatorPopover(browser)
await browser.elementByCss('[data-preferences]').click()
await browser.elementByCss('[data-hide-dev-tools]').click()
await waitForIssue(browser)
await installCheckCompilingKeepsDisabledIssue(browser)
await browser.elementByCss('#to-disabled-slow').click()
await retry(async () => {
expect(
await browser.eval(
`sessionStorage.getItem('keptDisabledIssueWhileCompiling')`
)
).toBe('true')
})
await retry(async () => {
expect(await browser.elementByCss('main > p').text()).toBe(
'Disabled slow page'
)
})
})
})
module.exports = {
turbopack: {
rules: {
'*.slow.js': {
loaders: ['./slow-loader.js'],
as: '*.js',
},
},
},
webpack(config) {
config.module.rules.push({
test: /\.slow\.js$/,
use: [require.resolve('./slow-loader.js')],
})
return config
},
}
module.exports = function slowLoader(source) {
const callback = this.async()
setTimeout(() => callback(null, source), 1000)
}
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