Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add editor links to RSC build error #45179

Merged
merged 27 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7f0c9b7
Add error name
Jan 23, 2023
ccf20a9
Move open editor to helper hook
Jan 23, 2023
560ecc3
Add component that converts file paths to links
Jan 23, 2023
2b5912b
Use new component for build errors
Jan 23, 2023
7459956
Add test
Jan 23, 2023
a691ce4
Merge branch 'canary' into rsc-error-editor-links
hanneslund Jan 23, 2023
999b644
Fix test
Jan 23, 2023
9563a91
Merge branch 'canary' into rsc-error-editor-links
hanneslund Jan 23, 2023
da49b50
Try restarting next
Jan 23, 2023
769cf1b
Add snapshot
Jan 23, 2023
95e52fd
Merge branch 'canary' into rsc-error-editor-links
hanneslund Jan 23, 2023
8af3179
Update snapshot
Jan 23, 2023
bb38829
Remove restart next in test
Jan 23, 2023
43f10da
fix?
Jan 23, 2023
ca3b23a
Merge branch 'canary' into rsc-error-editor-links
ijjk Jan 23, 2023
9299659
Fix test todos
Jan 24, 2023
b66c7de
Merge branch 'canary' into rsc-error-editor-links
hanneslund Jan 24, 2023
d1f0692
Wait for redboxheader
Jan 24, 2023
d911289
Merge branch 'canary' of https://github.com/hanneslund/next.js into r…
Jan 24, 2023
2111183
Refactor to function and find links on full content
Jan 24, 2023
bd3a3c0
Merge branch 'canary' into rsc-error-editor-links
hanneslund Jan 24, 2023
8494c44
add check to test
Jan 24, 2023
d32637b
Update check
Jan 24, 2023
b76ef65
Port rsc tests to acceptance-app to use the helpers
Jan 24, 2023
97495f6
Fix lint
Jan 24, 2023
21e623b
Merge branch 'canary' of https://github.com/hanneslund/next.js into r…
Jan 24, 2023
54d4831
Merge branch 'canary' into rsc-error-editor-links
kodiakhq[bot] Jan 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ export function getRscError(

const error = new SimpleWebpackError(
fileName,
formattedError[0] +
'ReactServerComponentsError:\n' +
formattedError[0] +
formattedError[1] +
moduleTrace
.map((m) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react'
import { useOpenInEditor } from '../../helpers/use-open-in-editor'

export function EditorLink({ file }: { file: string }) {
const open = useOpenInEditor({
file,
column: 1,
lineNumber: 1,
})

return (
<div
data-with-open-in-editor-link
tabIndex={10}
role={'link'}
onClick={open}
title={'Click to open in your editor'}
>
{file}
<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>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
import Anser from 'next/dist/compiled/anser'
import * as React from 'react'
import { EditorLink } from './EditorLink'

export type TerminalProps = { content: string }

function getImportTraceFiles(content: string): [string, string[]] {
if (/ReactServerComponentsError:/.test(content)) {
// It's an RSC Build Error
const lines = content.split('\n')

// Grab the lines at the end containing the files
const files = []
while (/app\/.+\./.test(lines[lines.length - 1])) {
const file = lines.pop()!.trim()
files.unshift(file)
}

return [lines.join('\n'), files]
}

return [content, []]
}

export const Terminal: React.FC<TerminalProps> = function Terminal({
content,
}) {
const [source, editorLinks] = React.useMemo(
() => getImportTraceFiles(content),
[content]
)

const decoded = React.useMemo(() => {
return Anser.ansiToJson(content, {
return Anser.ansiToJson(source, {
json: true,
use_classes: true,
remove_empty: true,
})
}, [content])
}, [source])

return (
<div data-nextjs-terminal>
Expand All @@ -32,6 +56,9 @@ export const Terminal: React.FC<TerminalProps> = function Terminal({
{entry.content}
</span>
))}
{editorLinks.map((file) => (
<EditorLink key={file} file={file} />
))}
</pre>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ const styles = css`
white-space: pre-wrap;
word-break: break-word;
}

[data-with-open-in-editor-link] svg {
width: auto;
height: var(--size-font-small);
margin-left: var(--size-gap);
}
[data-with-open-in-editor-link] {
cursor: pointer;
}
[data-with-open-in-editor-link]:hover {
text-decoration: underline dotted;
}
[data-with-open-in-editor-link] {
margin-left: var(--size-gap-double);
}
`

export { styles }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import dynamic from 'next/dynamic'

const Component = dynamic(async () => undefined, { ssr: false })
const Component = dynamic(async () => () => <p>hello dynamic world</p>, {
ssr: false,
})

export default function Page() {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'server-only'
// import 'server-only'

export default function ServerOnlyLib() {
return 'server-only-lib'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// import { useState } from 'react'
export default function Component() {
return <div>Component</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Component from './component'

export default function Page() {
return <Component />
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'client-only'
// import 'client-only'

export default function ClientOnlyLib() {
return 'client-only-lib'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p>Page</p>
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line no-unused-vars
import React from 'react'

// 'use client'
Expand Down
6 changes: 4 additions & 2 deletions test/development/acceptance-app/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { NextInstance } from 'test/lib/next-modes/base'

export async function sandbox(
next: NextInstance,
initialFiles?: Map<string, string>
initialFiles?: Map<string, string>,
initialUrl: string = '/',
webDriverOptions: any = undefined
) {
await next.stop()
await next.clean()
Expand All @@ -20,7 +22,7 @@ export async function sandbox(
}
}
await next.start()
const browser = await webdriver(next.url, '/')
const browser = await webdriver(next.url, initialUrl, webDriverOptions)
return {
browser,
session: {
Expand Down