Unverified Commit a0e61716 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Show dev overlay errors before the indicator state is known (#100629)

## Summary

In development, the dev overlay renders nothing until the HMR `sync`
message arrives. That message tells the client whether the dev indicator
is disabled, and the client waits for it so a disabled indicator doesn't
briefly appear. The error overlay (redbox) sat behind the same check,
though. If `sync` was delayed or lost, compile and runtime errors
already reached the client state but no redbox was shown.

This PR keeps the indicator-readiness check only for the indicator UI,
meaning the devtools indicator and its panels. The error overlay and the
contexts it needs now render independently of it, so errors show as soon
as they are known. When `sync` arrives normally, the indicator behaves
the same as before.

#100628 removes the server-side cause of a delayed `sync` (waiting on
the npm registry version check). This change is independent and protects
the overlay from any other delay.

A regression test uses Playwright websocket routing to withhold only the
`sync` message. For both the app and pages router, it checks that a
module-not-found error still shows the redbox and that the devtools
indicator stays hidden.

## Verification

Run locally with Turbopack dev and webpack dev:

- New `test/development/app-dir/dev-overlay-redbox-before-sync`: fails
without this change (no redbox) and passes with it.
- `test/development/acceptance/ReactRefreshLogBox-builtins.test.ts`
-
`test/development/acceptance-app/rsc-build-errors-react-apis-1.test.ts`
- `test/development/dev-indicator/dev-indicator.test.ts`
- `test/development/app-dir/dev-indicator/hide-button.test.ts`

<!-- NEXT_JS_LLM -->


<!-- fleet 64c837ee-843c-4c4b-b256-57dd903babf5 -->
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent 88d72694
......@@ -64,46 +64,44 @@ export function DevOverlay() {
instantErrorCount,
}) => {
return (
<>
{state.showIndicator ? (
<>
<RenderErrorContext
value={{
runtimeErrors,
totalErrorCount:
totalErrorCount +
(state.hasVulnerabilityInsight ? 1 : 0),
normalErrorCount,
instantErrorCount:
instantErrorCount +
(state.hasVulnerabilityInsight ? 1 : 0),
}}
>
<PanelRouterContext
value={{
panel,
setPanel,
triggerRef,
selectedIndex,
setSelectedIndex,
}}
>
<ErrorOverlay
state={state}
dispatch={dispatch}
getSquashedHydrationErrorDetails={
getSquashedHydrationErrorDetails
}
runtimeErrors={runtimeErrors}
errorCount={totalErrorCount}
/>
<PanelRouter />
<DevToolsIndicator />
</PanelRouterContext>
</RenderErrorContext>
</>
) : null}
</>
<RenderErrorContext
value={{
runtimeErrors,
totalErrorCount:
totalErrorCount + (state.hasVulnerabilityInsight ? 1 : 0),
normalErrorCount,
instantErrorCount:
instantErrorCount + (state.hasVulnerabilityInsight ? 1 : 0),
}}
>
<PanelRouterContext
value={{
panel,
setPanel,
triggerRef,
selectedIndex,
setSelectedIndex,
}}
>
{/* Errors must show even before the server's HMR `sync` message
tells us whether the indicator is disabled. */}
<ErrorOverlay
state={state}
dispatch={dispatch}
getSquashedHydrationErrorDetails={
getSquashedHydrationErrorDetails
}
runtimeErrors={runtimeErrors}
errorCount={totalErrorCount}
/>
{state.showIndicator ? (
<>
<PanelRouter />
<DevToolsIndicator />
</>
) : null}
</PanelRouterContext>
</RenderErrorContext>
)
}}
</RenderError>
......
import type { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return <p>hello world</p>
}
import { nextTestSetup } from 'e2e-utils'
import { getRedboxDescription, waitForRedbox } from 'next-test-utils'
describe.each([
{
router: 'app router',
pathname: '/',
file: 'app/page.tsx',
content: 'hello world',
},
{
router: 'pages router',
pathname: '/pages-router',
file: 'pages/pages-router.tsx',
content: 'hello pages',
},
])(
'dev-overlay-redbox-before-sync ($router)',
({ pathname, file, content }) => {
const { next } = nextTestSetup({
files: __dirname,
})
it('shows build errors before the HMR sync message arrives', async () => {
const browser = await next.browser(pathname, {
async beforePageLoad(page) {
// Withhold the `sync` message, e.g. as if the server were still waiting
// for slow data, so the dev overlay never learns the indicator state.
await page.routeWebSocket(/\/_next\/hmr/, (clientSocket) => {
const serverSocket = clientSocket.connectToServer()
serverSocket.onMessage((message) => {
if (
typeof message === 'string' &&
JSON.parse(message).type === 'sync'
) {
return
}
clientSocket.send(message)
})
clientSocket.onMessage((message) => serverSocket.send(message))
})
},
})
expect(await browser.elementByCss('p').text()).toBe(content)
await next.patchFile(file, (source) =>
source!.replace(
'export default function Page',
"import 'does-not-exist'\n\nexport default function Page"
)
)
await waitForRedbox(browser)
expect(await getRedboxDescription(browser)).toBe(
"Module not found: Can't resolve 'does-not-exist'"
)
// The indicator is still hidden until its state is known.
expect(await browser.locateDevToolsIndicator().count()).toBe(0)
})
}
)
export default function Page() {
return <p>hello pages</p>
}
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