Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix playground exceptions #1931

Merged
merged 6 commits into from Feb 7, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/_component/editor.client.js
Expand Up @@ -119,6 +119,17 @@ export const Editor = ({children}) => {
)
const stats = state.file ? statistics(state.file) : {}

// Create a preview component that can handle errors with try-catch block; for catching invalid JS expressions errors
const Preview = useCallback(() => {
try {
return state.file.result();
xHomu marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
return (<pre>
<code>{String(error.message)}</code>
</pre>);
xHomu marked this conversation as resolved.
Show resolved Hide resolved
}
}, [state]);

xHomu marked this conversation as resolved.
Show resolved Hide resolved
return (
<div>
<Tabs className="frame">
Expand Down Expand Up @@ -234,7 +245,7 @@ export const Editor = ({children}) => {
<div className="frame-body frame-body-box-fixed-height frame-body-box">
{state.file && state.file.result ? (
<ErrorBoundary FallbackComponent={FallbackComponent}>
{state.file.result()}
<Preview />
</ErrorBoundary>
xHomu marked this conversation as resolved.
Show resolved Hide resolved
) : null}
</div>
Expand Down