Skip to content

Commit 71bc6ff

Browse files
authored
Fix playground exceptions (#1931)
Closes GH-1772. Reviewed-by: Christian Murphy <[email protected]> Reviewed-by: Titus Wormer <[email protected]>
1 parent 4b514e1 commit 71bc6ff

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

docs/_component/editor.client.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ export const Editor = ({children}) => {
119119
)
120120
const stats = state.file ? statistics(state.file) : {}
121121

122+
// Create a preview component that can handle errors with try-catch block; for catching invalid JS expressions errors that ErrorBoundary cannot catch.
123+
const Preview = useCallback(() => {
124+
try {
125+
return state.file.result()
126+
} catch (error) {
127+
return <FallbackComponent error={error} />
128+
}
129+
}, [state])
130+
122131
return (
123132
<div>
124133
<Tabs className="frame">
@@ -232,11 +241,7 @@ export const Editor = ({children}) => {
232241
<TabPanel>
233242
<noscript>Enable JavaScript for the rendered result.</noscript>
234243
<div className="frame-body frame-body-box-fixed-height frame-body-box">
235-
{state.file && state.file.result ? (
236-
<ErrorBoundary FallbackComponent={FallbackComponent}>
237-
{state.file.result()}
238-
</ErrorBoundary>
239-
) : null}
244+
{state.file && state.file.result ? <Preview /> : null}
240245
</div>
241246
</TabPanel>
242247
<TabPanel>

0 commit comments

Comments
 (0)