Skip to content

Commit a70c77b

Browse files
committed
added fix for playground errors
1 parent 0366d24 commit a70c77b

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

docs/client/components/PlaygroundPage/PlaygroundWithPreview/Preview.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,37 +54,42 @@ class Preview extends React.Component {
5454
executeCode () {
5555
const mountNode = this.refs.mount;
5656
const scope = this.buildScope(mountNode);
57-
57+
if (this.state.error) {
58+
this.setState({ error: null });
59+
}
60+
5861
try {
5962
ReactDOM.unmountComponentAtNode(mountNode);
6063
} catch (e) {
61-
console.log(e);
64+
6265
}
66+
6367
try {
64-
6568
const x = eval(this.compileCode())(...scope);
6669
ReactDOM.render(x, mountNode);
6770
if (this.state.error) {
6871
this.setState({ error: null });
6972
}
7073
} 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);
7579
}
7680
}
7781

7882
render () {
79-
if (this.state.error) {
80-
return (
81-
<div className={styles.error}>
82-
{this.state.error}
83-
</div>
84-
)
85-
}
83+
8684
return (
8785
<div className={styles.preview}>
86+
{
87+
this.state.error !== null ? (
88+
<div className="error">
89+
{this.state.error}
90+
</div>
91+
) : null
92+
}
8893
<div ref="mount" />
8994
</div>
9095
);

docs/client/components/PlaygroundPage/PlaygroundWithPreview/styles.scss

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@
3434
left: 60%;
3535
width: 35%;
3636
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+
}
4540
}

0 commit comments

Comments
 (0)