Unverified Commit 8324d810 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

[segment explorer] handle custom error boundary (#80714)

Display custom error boundary `error.js` in segement explorer when it's rendered

![image](https://github.com/user-attachments/assets/4abad442-0703-4609-8202-b4f41f007afe)

Closes NEXT-4331
parent 9d4239a1
......@@ -260,4 +260,9 @@ export const DEV_TOOLS_INFO_RENDER_FILES_STYLES = css`
background-color: var(--color-green-300);
color: var(--color-green-900);
}
.segment-explorer-file-label--error,
.segment-explorer-file-label--global-error {
background-color: var(--color-red-300);
color: var(--color-red-900);
}
`
......@@ -544,18 +544,26 @@ async function createComponentTreeInternal({
</Template>
)
const templateFilePath = getConventionPathByType(
parallelRoute,
dir,
'template'
)
const templateFilePath = getConventionPathByType(tree, dir, 'template')
const errorFilePath = getConventionPathByType(tree, dir, 'error')
const wrappedErrorStyles =
isSegmentViewEnabled && errorFilePath ? (
<SegmentViewNode type="error" pagePath={errorFilePath}>
{errorStyles}
</SegmentViewNode>
) : (
errorStyles
)
return [
parallelRouteKey,
<LayoutRouter
parallelRouterKey={parallelRouteKey}
// TODO-APP: Add test for loading returning `undefined`. This currently can't be tested as the `webdriver()` tab will wait for the full page to load before returning.
error={ErrorComponent}
errorStyles={errorStyles}
errorStyles={wrappedErrorStyles}
errorScripts={errorScripts}
template={
// Only render SegmentViewNode when there's an actual template
......
.error-title {
color: red;
font-size: 24px;
font-weight: bold;
}
'use client'
import './error.css'
export default function CustomError() {
return <h2 className="error-title">Custom Error</h2>
}
'use client'
export default function Page() {
if (typeof window !== 'undefined') {
throw new Error('Error on client')
}
return <p>page</p>
}
......@@ -179,4 +179,14 @@ describe('segment-explorer', () => {
loading.tsx"
`)
})
it('should show the custom error boundary when present', async () => {
const browser = await next.browser('/runtime-error/boundary')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/
layout.tsx
runtime-error / boundary/
error.tsx"
`)
})
})
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