File tree Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 1+ /** @jsx createElement */
2+
3+ import { ErrorInfo , ReactNode } from 'react' ;
4+ import { PureComponent , createElement } from '../ui-react/common' ;
5+
6+ interface Props {
7+ readonly children : ReactNode ;
8+ }
9+
10+ interface State {
11+ e : 0 | 1 ;
12+ }
13+
14+ export class ErrorBoundary extends PureComponent < Props , State > {
15+ constructor ( props : Props ) {
16+ super ( props ) ;
17+ this . state = { e : 0 } ;
18+ }
19+
20+ static getDerivedStateFromError = ( ) => ( { e : 1 } ) ;
21+
22+ // eslint-disable-next-line react/no-arrow-function-lifecycle
23+ componentDidCatch = ( error : Error , info : ErrorInfo ) =>
24+ // eslint-disable-next-line no-console
25+ console . error ( error , info . componentStack ) ;
26+
27+ render ( ) {
28+ return this . state . e ? (
29+ < span className = "warn" >
30+ Inspector error: please see console for details.
31+ </ span >
32+ ) : (
33+ this . props . children
34+ ) ;
35+ }
36+ }
Original file line number Diff line number Diff line change 22
33import { OPEN_VALUE , POSITION_VALUE } from './common' ;
44import { Body } from './Body' ;
5+ import { ErrorBoundary } from './ErrorBoundary' ;
56import { Header } from './Header' ;
67import { StoreProp } from './types' ;
78import { createElement } from '../ui-react/common' ;
@@ -13,7 +14,9 @@ export const Panel = ({s}: StoreProp) => {
1314 return useValue ( OPEN_VALUE , s ) ? (
1415 < main data-position = { position } >
1516 < Header s = { s } />
16- < Body s = { s } />
17+ < ErrorBoundary >
18+ < Body s = { s } />
19+ </ ErrorBoundary >
1720 </ main >
1821 ) : null ;
1922} ;
Original file line number Diff line number Diff line change @@ -85,6 +85,8 @@ export const APP_STYLESHEET = arrayJoin(
8585 'button.next' : 'margin-right:0.5rem' ,
8686 [ `th,#${ UNIQUE_ID } td` ] :
8787 'overflow:hidden;text-overflow:ellipsis;padding:0.25rem 0.5rem;max-width:12rem;white-space:nowrap;border-width:1px 0;border-style:solid;border-color:#777;text-align:left' ,
88+
89+ 'span.warn' : 'margin:0.25rem;color:#d81b60' ,
8890 } ,
8991 ( style , selector ) => ( style ? `#${ UNIQUE_ID } ${ selector } {${ style } }` : '' ) ,
9092 ) ,
Original file line number Diff line number Diff line change @@ -7,8 +7,9 @@ import {Store} from '../types/store';
77import { isUndefined } from '../common/other' ;
88
99export const {
10- createElement ,
10+ PureComponent ,
1111 Fragment,
12+ createElement,
1213 useCallback,
1314 useLayoutEffect,
1415 useRef,
You can’t perform that action at this time.
0 commit comments