Skip to content

Commit

Permalink
Fix playground exceptions (#1931)
Browse files Browse the repository at this point in the history
Closes GH-1772.

Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
xHomu committed Feb 7, 2022
1 parent 4b514e1 commit 71bc6ff
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions docs/_component/editor.client.js
Expand Up @@ -119,6 +119,15 @@ 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 that ErrorBoundary cannot catch.
const Preview = useCallback(() => {
try {
return state.file.result()
} catch (error) {
return <FallbackComponent error={error} />
}
}, [state])

return (
<div>
<Tabs className="frame">
Expand Down Expand Up @@ -232,11 +241,7 @@ export const Editor = ({children}) => {
<TabPanel>
<noscript>Enable JavaScript for the rendered result.</noscript>
<div className="frame-body frame-body-box-fixed-height frame-body-box">
{state.file && state.file.result ? (
<ErrorBoundary FallbackComponent={FallbackComponent}>
{state.file.result()}
</ErrorBoundary>
) : null}
{state.file && state.file.result ? <Preview /> : null}
</div>
</TabPanel>
<TabPanel>
Expand Down

1 comment on commit 71bc6ff

@vercel
Copy link

@vercel vercel bot commented on 71bc6ff Feb 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

Please sign in to comment.