forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fast Refresh] New Overlay for Prerender Error (vercel#12485)
- Loading branch information
Showing
17 changed files
with
351 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/react-dev-overlay/src/internal/helpers/getRawSourceMap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import dataUriToBuffer, { MimeBuffer } from 'data-uri-to-buffer' | ||
import { RawSourceMap } from 'source-map' | ||
import { getSourceMapUrl } from './getSourceMapUrl' | ||
|
||
export function getRawSourceMap(fileContents: string): RawSourceMap | null { | ||
const sourceUrl = getSourceMapUrl(fileContents) | ||
if (sourceUrl == null) { | ||
return null | ||
} | ||
|
||
let buffer: MimeBuffer | ||
try { | ||
buffer = dataUriToBuffer(sourceUrl) | ||
} catch (err) { | ||
console.error('Failed to parse source map URL:', err) | ||
return null | ||
} | ||
|
||
if (buffer.type !== 'application/json') { | ||
console.error(`Unknown source map type: ${buffer.typeFull}.`) | ||
return null | ||
} | ||
|
||
try { | ||
return JSON.parse(buffer.toString()) | ||
} catch { | ||
console.error('Failed to parse source map.') | ||
return null | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/react-dev-overlay/src/internal/helpers/getSourceMapUrl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function getSourceMapUrl(fileContents: string): string | null { | ||
const regex = /\/\/[#@] ?sourceMappingURL=([^\s'"]+)\s*$/gm | ||
let match = null | ||
for (;;) { | ||
let next = regex.exec(fileContents) | ||
if (next == null) { | ||
break | ||
} | ||
match = next | ||
} | ||
if (!(match && match[1])) { | ||
return null | ||
} | ||
return match[1].toString() | ||
} |
54 changes: 54 additions & 0 deletions
54
packages/react-dev-overlay/src/internal/helpers/nodeStackFrames.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { parse, StackFrame } from 'stacktrace-parser' | ||
|
||
export function getFilesystemFrame(frame: StackFrame): StackFrame { | ||
const f: StackFrame = { ...frame } | ||
|
||
if (typeof f.file === 'string') { | ||
if ( | ||
// Posix: | ||
f.file.startsWith('/') || | ||
// Win32: | ||
/^[a-z]:\\/i.test(f.file) || | ||
// Win32 UNC: | ||
f.file.startsWith('\\\\') | ||
) { | ||
f.file = `file://${f.file}` | ||
} | ||
} | ||
|
||
return f | ||
} | ||
|
||
export function getNodeError(error: Error): Error { | ||
let n: Error | ||
try { | ||
throw new Error(error.message) | ||
} catch (e) { | ||
n = e | ||
} | ||
|
||
n.name = error.name | ||
try { | ||
n.stack = parse(error.stack) | ||
.map(getFilesystemFrame) | ||
.map(f => { | ||
let str = ` at ${f.methodName}` | ||
if (f.file) { | ||
let loc = f.file | ||
if (f.lineNumber) { | ||
loc += `:${f.lineNumber}` | ||
if (f.column) { | ||
loc += `:${f.column}` | ||
} | ||
} | ||
str += ` (${loc})` | ||
} | ||
return str | ||
}) | ||
.join('\n') | ||
} catch { | ||
n.stack = error.stack | ||
} | ||
|
||
return n | ||
} |
Oops, something went wrong.