File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff 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 >
You can’t perform that action at this time.
0 commit comments