Fork me on GitHub
#rum
<
2017-04-20
>
jeroenvandijk13:04:41

is there a way to prevent exceptions from breaking the React tree structure? E.g. when I make a (javascript) syntax error, say (.useSomeUnknownMethod obj) in a component definition this forces me to refresh the app. I would like to fix it and not having to refresh my browser

jeroenvandijk13:04:58

I’m guessing this could be done by wrapping the render method with a try/catch (but I would have to do monkey patch to do this globally, without introducing new mixins)

tonsky16:04:54

hmm. What behaviour would you expect? What happens in pure react?

tonsky16:04:08

I’ll rephrase: what exactly breaks so that you have to reload?

jeroenvandijk20:04:42

@tonsky So I’m editting my rendered application with figwheel and I introduce a runtime error in my view e.g. (.getasdfa data). I’m getting an error as expected:

edit.cljs?rel=1492721696559:393 Uncaught TypeError: data.getasdfa is not a function
    at Function.<anonymous> (edit.cljs?rel=1492721696559:393)
    at Function.cljs.core.apply.cljs$core$IFn$_invoke$arity$2 (core.cljs:3685)
    at cljs$core$apply (core.cljs:3676)
    at render (core.cljs?rel=1491307518599:130)
    at subscriptive.cljs?rel=1491911411675:48
    at Object.render (core.cljs?rel=1491307518599:83)
    at react-dom.inc.js:5250
    at measureLifeCyclePerf (react-dom.inc.js:4529)
    at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (react-dom.inc.js:5249)
    at ReactCompositeComponentWrapper._renderValidatedComponent (react-dom.inc.js:5276)
After fixing the introducted mistake, figwheel reloads, but the app doesn’t want to load the new code anymore until I do a full refresh of the app:
react-dom.inc.js:11559 Uncaught TypeError: Cannot read property 'getHostNode' of null
        at Object.getHostNode (react-dom.inc.js:11559)
        at ReactCompositeComponentWrapper.getHostNode (react-dom.inc.js:4838)
        at Object.getHostNode (react-dom.inc.js:11559)
        at Object.updateChildren (react-dom.inc.js:4336)
        at ReactDOMComponent._reconcilerUpdateChildren (react-dom.inc.js:10399)
        at ReactDOMComponent._updateChildren (react-dom.inc.js:10503)
        at ReactDOMComponent.updateChildren (react-dom.inc.js:10490)
        at ReactDOMComponent._updateDOMChildren (react-dom.inc.js:6403)
        at ReactDOMComponent.updateComponent (react-dom.inc.js:6221)
        at ReactDOMComponent.receiveComponent (react-dom.inc.js:6183)
        
I think it would be an improvement if the first exception didn’t break future code updates (via figwheel). I don’t understand the React internals enough (yet) to see how complicated this might be.

jeroenvandijk21:04:54

My work around now is to set an alert with the text “Uncaught fatal exception, check the logs and restart the app” whenever an error with “getHostNode” is being detected by window.onerror