Unverified Commit fb20d9af authored by Sam Selikoff's avatar Sam Selikoff Committed by GitHub

Make error overlay editor actions easier to discover (#100206)

Make the "Open in editor" button easier to discover in the error
overlay. Updates the icon to a Code Wrap icon from Geist.

<img width="1984" height="788" alt="image"
src="https://github.com/user-attachments/assets/5e633c6a-f4cd-48f9-8925-b42981f20a4b"
/>

<!-- NEXT_JS_LLM -->
parent 169ab67e
import type { OriginalStackFrame } from '../../../shared/stack-frame'
import { HotlinkedText } from '../hot-linked-text'
import { ExternalIcon, SourceMappingErrorIcon } from '../../icons/external'
import { SourceMappingErrorIcon } from '../../icons/external'
import { CodeIcon } from '../../icons/code'
import { getStackFrameFile } from '../../../shared/stack-frame'
import { useOpenInEditor } from '../../utils/use-open-in-editor'
......@@ -40,11 +41,12 @@ export const CallStackFrame: React.FC<{
<HotlinkedText text={f.methodName} />
{hasOriginalCodeFrame && (
<button
type="button"
onClick={open}
className="open-in-editor-button"
className="call-stack-frame-editor-button"
aria-label={`Open ${f.methodName} in editor`}
>
<ExternalIcon width={16} height={16} />
<CodeIcon width={16} height={16} aria-hidden="true" />
</button>
)}
{frame.error ? (
......@@ -112,7 +114,7 @@ export const CALL_STACK_FRAME_STYLES = `
}
}
.open-in-editor-button, .source-mapping-error-button {
.call-stack-frame-editor-button, .source-mapping-error-button {
display: flex;
align-items: center;
justify-content: center;
......
import type { ReactNode } from 'react'
import { ExternalIcon } from '../../icons/external'
import { OpenInEditorButton } from '../open-in-editor-button'
type CodeFrameShellProps = {
header: ReactNode
......@@ -24,14 +24,11 @@ export function CodeFrameShell({
<p className="code-frame-link">
{header}
{onOpen && (
<button
aria-label={openLabel ?? 'Open in editor'}
<OpenInEditorButton
aria-label={openLabel}
data-with-open-in-editor-link-source-file
onClick={onOpen}
type="button"
>
<ExternalIcon />
</button>
/>
)}
</p>
</div>
......
......@@ -128,11 +128,6 @@ export const CODE_FRAME_STYLES = `
flex-shrink: 0;
}
[data-with-open-in-editor-link-source-file] svg {
width: var(--size-14);
height: var(--size-14);
}
.code-frame-lines {
min-width: max-content;
}
......@@ -140,6 +135,8 @@ export const CODE_FRAME_STYLES = `
.code-frame-link [data-text] {
font-size: var(--size-12);
text-align: left;
min-width: 0;
overflow-wrap: anywhere;
}
.code-frame-header {
......@@ -149,27 +146,7 @@ export const CODE_FRAME_STYLES = `
}
[data-with-open-in-editor-link-source-file] {
display: flex;
align-items: center;
justify-content: center;
width: var(--size-24);
height: var(--size-24);
padding: 4px;
margin-left: auto;
border-radius: var(--rounded-full);
&:focus-visible {
outline: var(--focus-ring);
outline-offset: -2px;
}
&:hover {
background: var(--color-gray-alpha-100);
}
&:active {
background: var(--color-gray-alpha-200);
}
}
[data-nextjs-codeframe]::selection,
......@@ -177,7 +154,7 @@ export const CODE_FRAME_STYLES = `
background-color: var(--color-ansi-selection);
}
[data-nextjs-codeframe] *:not(a) {
[data-nextjs-codeframe] *:not(a):not(.open-in-editor-button) {
color: inherit;
background-color: transparent;
font-family: var(--font-stack-monospace);
......
import type { ButtonHTMLAttributes } from 'react'
import { CodeIcon } from '../icons/code'
export function OpenInEditorButton(
props: ButtonHTMLAttributes<HTMLButtonElement>
) {
return (
<button type="button" {...props} className="open-in-editor-button">
<CodeIcon aria-hidden="true" />
Open in Editor
</button>
)
}
export const OPEN_IN_EDITOR_BUTTON_STYLES = `
.open-in-editor-button {
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
gap: 6px;
height: var(--size-28);
padding: 0 10px;
border: 1px solid var(--color-gray-400);
border-radius: var(--rounded-lg);
color: var(--color-gray-1000);
background: var(--color-background-100);
font-family: var(--font-stack-sans);
font-size: var(--size-12);
font-weight: 500;
line-height: var(--size-16);
white-space: nowrap;
cursor: pointer;
svg {
width: var(--size-12);
height: var(--size-12);
}
&:focus-visible {
outline: var(--focus-ring);
outline-offset: 2px;
}
&:hover {
background: var(--color-gray-alpha-100);
}
&:active {
background: var(--color-gray-alpha-200);
}
}
`
import { CodeIcon } from '../../icons/code'
import './segment-explorer.css'
import {
useSegmentTree,
......@@ -496,23 +497,3 @@ function BackArrowIcon() {
</svg>
)
}
function CodeIcon(props: React.SVGProps<SVGSVGElement>) {
return (
<svg
width="12"
height="12"
strokeLinejoin="round"
viewBox="0 0 16 16"
fill="currentColor"
{...props}
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M7.22763 14.1819L10.2276 2.18193L10.4095 1.45432L8.95432 1.09052L8.77242 1.81812L5.77242 13.8181L5.59051 14.5457L7.04573 14.9095L7.22763 14.1819ZM3.75002 12.0607L3.21969 11.5304L0.39647 8.70713C0.00594559 8.31661 0.00594559 7.68344 0.39647 7.29292L3.21969 4.46969L3.75002 3.93936L4.81068 5.00002L4.28035 5.53035L1.81068 8.00003L4.28035 10.4697L4.81068 11L3.75002 12.0607ZM12.25 12.0607L12.7804 11.5304L15.6036 8.70713C15.9941 8.31661 15.9941 7.68344 15.6036 7.29292L12.7804 4.46969L12.25 3.93936L11.1894 5.00002L11.7197 5.53035L14.1894 8.00003L11.7197 10.4697L11.1894 11L12.25 12.0607Z"
fill="currentColor"
/>
</svg>
)
}
import { OpenInEditorButton } from '../open-in-editor-button'
import { useOpenInEditor } from '../../utils/use-open-in-editor'
type EditorLinkProps = {
......@@ -19,40 +20,28 @@ export function EditorLink({ file, location }: EditorLinkProps) {
<div
data-with-open-in-editor-link
data-with-open-in-editor-link-import-trace
role={'link'}
onClick={open}
title={'Click to open in your editor'}
>
{file}
{location ? `:${location.line}:${location.column}` : null}
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path>
<polyline points="15 3 21 3 21 9"></polyline>
<line x1="10" y1="14" x2="21" y2="3"></line>
</svg>
<span>
{file}
{location ? `:${location.line}:${location.column}` : null}
</span>
<OpenInEditorButton
onClick={open}
aria-label={`Open ${file} in editor`}
/>
</div>
)
}
export const EDITOR_LINK_STYLES = `
[data-with-open-in-editor-link] svg {
width: auto;
height: var(--size-14);
margin-left: 8px;
}
[data-with-open-in-editor-link] {
cursor: pointer;
}
[data-with-open-in-editor-link]:hover {
text-decoration: underline dotted;
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
margin-top: 8px;
white-space: normal;
overflow-wrap: anywhere;
}
[data-with-open-in-editor-link-import-trace] {
margin-left: 16px;
......
......@@ -2,7 +2,7 @@ import Anser from 'next/dist/compiled/anser'
import * as React from 'react'
import { HotlinkedText } from '../hot-linked-text'
import { EditorLink } from './editor-link'
import { ExternalIcon } from '../../icons/external'
import { OpenInEditorButton } from '../open-in-editor-button'
import { getStackFrameFile, type StackFrame } from '../../../shared/stack-frame'
import { useOpenInEditor } from '../../utils/use-open-in-editor'
import { FileIcon } from '../../icons/file'
......@@ -101,15 +101,10 @@ export const Terminal: React.FC<TerminalProps> = function Terminal({
{/* TODO: Unlike the CodeFrame component, the `methodName` is unavailable. */}
{getStackFrameFile(stackFrame)}
</span>
<button
aria-label="Open in editor"
<OpenInEditorButton
data-with-open-in-editor-link-source-file
onClick={open}
>
<span className="code-frame-icon" data-icon="right">
<ExternalIcon width={16} height={16} />
</span>
</button>
/>
</div>
</div>
<pre className="code-frame-pre">
......
import type { SVGProps } from 'react'
export function CodeIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg
width="12"
height="12"
strokeLinejoin="round"
viewBox="0 0 16 16"
fill="currentColor"
{...props}
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="m7.23 14.18 3-12 .18-.73-1.46-.36-.18.73-3 12-.18.73 1.46.36zm-3.48-2.12-.53-.53L.4 8.71a1 1 0 0 1 0-1.42l2.82-2.82.53-.53L4.81 5l-.53.53L1.81 8l2.47 2.47.53.53zm8.5 0 .53-.53 2.82-2.82a1 1 0 0 0 0-1.42l-2.82-2.82-.53-.53L11.19 5l.53.53L14.19 8l-2.47 2.47-.53.53z"
fill="currentColor"
/>
</svg>
)
}
import { OPEN_IN_EDITOR_BUTTON_STYLES } from '../components/open-in-editor-button'
import { CODE_FRAME_STYLES } from '../components/code-frame/code-frame'
import { styles as dialog } from '../components/dialog'
import { styles as errorLayout } from '../components/errors/error-overlay-layout/error-overlay-layout'
......@@ -34,6 +35,7 @@ export function ComponentStyles() {
${CODE_FRAME_STYLES}
${TERMINAL_STYLES}
${EDITOR_LINK_STYLES}
${OPEN_IN_EDITOR_BUTTON_STYLES}
${buildErrorStyles}
${containerErrorStyles}
${containerRuntimeErrorStyles}
......
......@@ -15,13 +15,13 @@ async function clickSourceFile(browser: Playwright) {
async function clickImportTraceFiles(browser: Playwright) {
await browser.waitForElementByCss(
'[data-with-open-in-editor-link-import-trace]'
'[data-with-open-in-editor-link-import-trace] button'
)
const collapsedFrameworkGroups = await browser.elementsByCss(
'[data-with-open-in-editor-link-import-trace]'
const editorButtons = await browser.elementsByCss(
'[data-with-open-in-editor-link-import-trace] button'
)
for (const collapsedFrameworkButton of collapsedFrameworkGroups) {
await collapsedFrameworkButton.click()
for (const editorButton of editorButtons) {
await editorButton.click()
}
}
......
......@@ -1232,8 +1232,15 @@ export async function getRedboxTotalErrorCount(
return parseInt(text || '-1')
}
export function getRedboxSource(browser: Playwright): Promise<string | null> {
return browser.eval(() => {
// Editor controls are not part of the source code captured by error snapshots.
function normalizeRedboxSource(source: string | null): string | null {
return source?.replace(/\nOpen in Editor(?=\n|$)/g, '') ?? null
}
export async function getRedboxSource(
browser: Playwright
): Promise<string | null> {
const source = await browser.eval(() => {
const portal = [].slice
.call(document.querySelectorAll('nextjs-portal'))
.find((p) =>
......@@ -1247,6 +1254,7 @@ export function getRedboxSource(browser: Playwright): Promise<string | null> {
?.innerText ?? null
)
})
return normalizeRedboxSource(source)
}
export function getRedboxTitle(browser: Playwright): Promise<string | null> {
......@@ -1677,7 +1685,7 @@ export interface RedboxCauseEntry {
export async function getRedboxCause(
browser: Playwright
): Promise<RedboxCauseEntry[] | null> {
return browser.eval(() => {
const entries = await browser.eval(() => {
const portal = [].slice
.call(document.querySelectorAll('nextjs-portal'))
.find((p) => p.shadowRoot.querySelector('[data-nextjs-dialog-header]'))
......@@ -1711,12 +1719,18 @@ export async function getRedboxCause(
}
return causes
})
return (
entries?.map((entry) => ({
...entry,
source: normalizeRedboxSource(entry.source),
})) ?? null
)
}
export async function getRedboxAggregateErrors(
browser: Playwright
): Promise<RedboxCauseEntry[] | null> {
return browser.eval(() => {
const entries = await browser.eval(() => {
const portal = [].slice
.call(document.querySelectorAll('nextjs-portal'))
.find((p) => p.shadowRoot.querySelector('[data-nextjs-dialog-header]'))
......@@ -1754,6 +1768,12 @@ export async function getRedboxAggregateErrors(
}
return entries
})
return (
entries?.map((entry) => ({
...entry,
source: normalizeRedboxSource(entry.source),
})) ?? null
)
}
export async function getRedboxCallStack(
......
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