-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fast Refresh] Redesigned Runtime Error Experience (#12222)
- Loading branch information
Showing
52 changed files
with
2,395 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,5 +37,5 @@ code:after { | |
hr { | ||
border: none; | ||
border-bottom: 1px solid #efefef; | ||
margin: 6em auto; | ||
margin: 5em auto; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/lib/ |
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,3 @@ | ||
# `@next/react-dev-overlay` | ||
|
||
A development-only overlay for developing React applications. |
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,31 @@ | ||
{ | ||
"name": "@next/react-dev-overlay", | ||
"version": "9.3.7-canary.1", | ||
"description": "A development-only overlay for developing React applications.", | ||
"repository": { | ||
"url": "zeit/next.js", | ||
"directory": "packages/react-dev-overlay" | ||
}, | ||
"files": [ | ||
"lib/" | ||
], | ||
"author": "Joe Haddad <timer@vercel.com>", | ||
"license": "MIT", | ||
"scripts": { | ||
"prepublish": "tsc -d -p tsconfig.json", | ||
"build": "tsc -d -w -p tsconfig.json" | ||
}, | ||
"dependencies": { | ||
"@babel/code-frame": "7.8.3", | ||
"anser": "1.4.9", | ||
"classnames": "2.2.6", | ||
"source-map": "0.7.3", | ||
"stacktrace-parser": "0.1.9", | ||
"strip-ansi": "6.0.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.9.0", | ||
"react-dom": "^16.9.0" | ||
}, | ||
"devDependencies": {} | ||
} |
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,79 @@ | ||
import { parse as parseStack } from 'stacktrace-parser' | ||
import * as Bus from './internal/bus' | ||
|
||
let isRegistered = false | ||
let stackTraceLimit: number | undefined = undefined | ||
|
||
function onUnhandledError(ev: ErrorEvent) { | ||
const error = ev?.error | ||
if (!error || !(error instanceof Error) || typeof error.stack !== 'string') { | ||
// A non-error was thrown, we don't have anything to show. :-( | ||
return | ||
} | ||
|
||
const e = error | ||
Bus.emit({ | ||
type: Bus.TYPE_UNHANDLED_ERROR, | ||
reason: error, | ||
frames: parseStack(e.stack), | ||
}) | ||
} | ||
|
||
function onUnhandledRejection(ev: PromiseRejectionEvent) { | ||
const reason = ev?.reason | ||
if ( | ||
!reason || | ||
!(reason instanceof Error) || | ||
typeof reason.stack !== 'string' | ||
) { | ||
// A non-error was thrown, we don't have anything to show. :-( | ||
return | ||
} | ||
|
||
const e = reason | ||
Bus.emit({ | ||
type: Bus.TYPE_UNHANDLED_REJECTION, | ||
reason: reason, | ||
frames: parseStack(e.stack), | ||
}) | ||
} | ||
|
||
function register() { | ||
if (isRegistered) { | ||
return | ||
} | ||
isRegistered = true | ||
|
||
try { | ||
const limit = Error.stackTraceLimit | ||
Error.stackTraceLimit = 50 | ||
stackTraceLimit = limit | ||
} catch {} | ||
|
||
window.addEventListener('error', onUnhandledError) | ||
window.addEventListener('unhandledrejection', onUnhandledRejection) | ||
} | ||
|
||
function unregister() { | ||
if (!isRegistered) { | ||
return | ||
} | ||
isRegistered = false | ||
|
||
if (stackTraceLimit !== undefined) { | ||
try { | ||
Error.stackTraceLimit = stackTraceLimit | ||
} catch {} | ||
stackTraceLimit = undefined | ||
} | ||
|
||
window.removeEventListener('error', onUnhandledError) | ||
window.removeEventListener('unhandledrejection', onUnhandledRejection) | ||
} | ||
|
||
function onRefresh() { | ||
Bus.emit({ type: Bus.TYPE_REFFRESH }) | ||
} | ||
|
||
export { default as ReactDevOverlay } from './internal/ReactDevOverlay' | ||
export { register, unregister, onRefresh } |
Oops, something went wrong.