Unverified Commit 7593039b authored by Balázs Orbán's avatar Balázs Orbán Committed by GitHub

fix(error-overlay): improve a11y, minor refactors (#62723)

### What?

- Use `button` instead of `span` to allow keyboard navigation
- match tabindex with other items in the overlay to include it in the
natural focus sequence
- the style is kept, but we might need a better contrasting icon for the
dark background
- use same file conventions with existing files
  - match file casing
  - move icons to the `icons` folder
- Improve PseudoHtml internal docs
  - use code guards ``` for code snippets
- drop the `any` type (long-term, we really should disallow `any` types)

Closes NEXT-2657
parent 2dab0b6e
import type { StackFramesGroup } from '../../helpers/group-stack-frames-by-framework'
import { CallStackFrame } from './CallStackFrame'
import { FrameworkIcon } from './FrameworkIcon'
export function CollapseIcon({ collapsed }: { collapsed?: boolean } = {}) {
// If is not collapsed, rotate 90 degrees
return (
<svg
data-nextjs-call-stack-chevron-icon
data-collapsed={collapsed}
fill="none"
height="20"
width="20"
shapeRendering="geometricPrecision"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
// rotate 90 degrees if not collapsed
{...(typeof collapsed === 'boolean'
? { style: { transform: collapsed ? undefined : 'rotate(90deg)' } }
: {})}
>
<path d="M9 18l6-6-6-6" />
</svg>
)
}
import { CollapseIcon } from '../../icons/CollapseIcon'
import { FrameworkIcon } from '../../icons/FrameworkIcon'
function FrameworkGroup({
framework,
......
import { useMemo, Fragment, useState } from 'react'
import type { ComponentStackFrame } from '../../helpers/parse-component-stack'
import { CollapseIcon } from './GroupedStackFrames'
import { CollapseIcon } from '../../icons/CollapseIcon'
// In total it will display 6 rows.
const MAX_NON_COLLAPSED_FRAMES = 6
......@@ -12,6 +12,7 @@ const MAX_NON_COLLAPSED_FRAMES = 6
*
* For html tags mismatch, it will render it for the code block
*
* ```
* <pre>
* <code>{`
* <Page>
......@@ -21,20 +22,21 @@ const MAX_NON_COLLAPSED_FRAMES = 6
* ^^^
* `}</code>
* </pre>
* ```
*
* For text mismatch, it will render it for the code block
*
* ```diff
* <pre>
* <code>{`
* <Page>
* <p>
* "Server Text" (red text as removed)
* "Client Text" (green text as added)
* - "Server Text"
* + "Client Text"
* </p>
* </Page>
* `}</code>
*
*
* ```
*/
export function PseudoHtmlDiff({
componentStackFrames,
......@@ -46,9 +48,8 @@ export function PseudoHtmlDiff({
componentStackFrames: ComponentStackFrame[]
serverContent: string
clientContent: string
[prop: string]: any
hydrationMismatchType: 'tag' | 'text'
}) {
} & React.HTMLAttributes<HTMLPreElement>) {
const isHtmlTagsWarning = hydrationMismatchType === 'tag'
const shouldCollapse = componentStackFrames.length > MAX_NON_COLLAPSED_FRAMES
const [isHtmlCollapsed, toggleCollapseHtml] = useState(shouldCollapse)
......@@ -157,12 +158,13 @@ export function PseudoHtmlDiff({
return (
<div data-nextjs-container-errors-pseudo-html>
<span
<button
tabIndex={10} // match CallStackFrame
data-nextjs-container-errors-pseudo-html-collapse
onClick={() => toggleCollapseHtml(!isHtmlCollapsed)}
>
<CollapseIcon collapsed={isHtmlCollapsed} />
</span>
</button>
<pre {...props}>
<code>{htmlComponents}</code>
</pre>
......
......@@ -195,6 +195,10 @@ export const styles = css`
position: absolute;
left: 10px;
top: 10px;
color: inherit;
background: none;
border: none;
padding: 0;
}
[data-nextjs-container-errors-pseudo-html--diff-add] {
color: var(--color-ansi-green);
......
export function CollapseIcon({ collapsed }: { collapsed?: boolean } = {}) {
return (
<svg
data-nextjs-call-stack-chevron-icon
data-collapsed={collapsed}
fill="none"
height="20"
width="20"
shapeRendering="geometricPrecision"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
// rotate 90 degrees if not collapsed.
// If collapsed isn't present, the rotation is applied via the `data-nextjs-collapsed-call-stack-details` element's `open` attribute
{...(typeof collapsed === 'boolean'
? { style: { transform: collapsed ? undefined : 'rotate(90deg)' } }
: {})}
>
<path d="M9 18l6-6-6-6" />
</svg>
)
}
import React from 'react'
import type { StackFramesGroup } from '../../helpers/group-stack-frames-by-framework'
import type { StackFramesGroup } from '../helpers/group-stack-frames-by-framework'
export function FrameworkIcon({
framework,
......
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