File tree Expand file tree Collapse file tree 2 files changed +22
-22
lines changed
docs/client/components/PlaygroundPage/PlaygroundWithPreview Expand file tree Collapse file tree 2 files changed +22
-22
lines changed Original file line number Diff line number Diff line change @@ -54,37 +54,42 @@ class Preview extends React.Component {
54
54
executeCode ( ) {
55
55
const mountNode = this . refs . mount ;
56
56
const scope = this . buildScope ( mountNode ) ;
57
-
57
+ if ( this . state . error ) {
58
+ this . setState ( { error : null } ) ;
59
+ }
60
+
58
61
try {
59
62
ReactDOM . unmountComponentAtNode ( mountNode ) ;
60
63
} catch ( e ) {
61
- console . log ( e ) ;
64
+
62
65
}
66
+
63
67
try {
64
-
65
68
const x = eval ( this . compileCode ( ) ) ( ...scope ) ;
66
69
ReactDOM . render ( x , mountNode ) ;
67
70
if ( this . state . error ) {
68
71
this . setState ( { error : null } ) ;
69
72
}
70
73
} catch ( err ) {
71
- console . log ( err ) ;
72
- this . setTimeout ( ( ) => {
73
- this . setState ( { error : err . toString ( ) } ) ;
74
- } , 500 ) ;
74
+ this . setTimeout ( ( ) => {
75
+ this . setState ( {
76
+ error : err . message ,
77
+ } ) ;
78
+ } , 100 ) ;
75
79
}
76
80
}
77
81
78
82
render ( ) {
79
- if ( this . state . error ) {
80
- return (
81
- < div className = { styles . error } >
82
- { this . state . error }
83
- </ div >
84
- )
85
- }
83
+
86
84
return (
87
85
< div className = { styles . preview } >
86
+ {
87
+ this . state . error !== null ? (
88
+ < div className = "error" >
89
+ { this . state . error }
90
+ </ div >
91
+ ) : null
92
+ }
88
93
< div ref = "mount" />
89
94
</ div >
90
95
) ;
Original file line number Diff line number Diff line change 34
34
left : 60% ;
35
35
width : 35% ;
36
36
height : 100% ;
37
- }
38
-
39
- :local(.error ) {
40
- position : fixed ;
41
- left : 60% ;
42
- width : 35% ;
43
- height : 100% ;
44
- color : red ;
37
+ .error {
38
+ color : red ;
39
+ }
45
40
}
You can’t perform that action at this time.
0 commit comments