Preact: JavaScript errors are not thrown in Firefox during rendering

Created on 8 Sep 2018  路  5Comments  路  Source: preactjs/preact

Developing with preact (no JSX, no build step) became almost impossible for me, because my syntax errors in render functions are not shown in the browser, they are just silently swallowed somewhere in preact internals, see this minimal example:

<html>

<head>
    <meta charset=utf8>
    <script src="https://unpkg.com/[email protected]/dist/preact.min.js"></script>
</head>

<div id=root>...</div>
<script>
    const { Component, h, render } = window.preact

    class App extends Component {
        constructor(props) {
            super(props)
        }
        componentDidMount() {
            this.setState({ stage:'choose-lesson' })
        }
        render() {
            if (this.state.stage == 'choose-lesson') {
                return h(TicketChoiceMenu, {})
            }
            else {
                return h('b',{},'oh')
            }
        }
    }

    function TicketChoiceMenu() {
        un = de.fi.ned // this is not reported in FireFox
        return 'bla'
    }

    render(h(App), root)

</script>

</html>

Although in Chrome everything is awesome.
I temporarily fixed this by wrapping buildFunctionalComponent in try catch with a log:

    function buildFunctionalComponent(vnode, context) {
      try{return vnode.nodeName(getNodeProps(vnode), context || EMPTY);}catch(e){console.log(e)}
    }

Most helpful comment

@andrewiggins I did not know preact 6 was not the latest one, switching to 8 fixed the problem, thank you!

All 5 comments

Firefox 61.0.2

@exebook I think buildFunctionalComponent wrapping issue is comming for this typo <div id=root>...</div> > <div id="root">...</div>. You may re-check your code once again

@rjoydip you mean double quotes around the div id parameter? No, it is irrelevant, I checked.

@exebook Hmm that's weird. Not sure why this is only happening in Firefox...

Side note: When I updated the the version of preact to the latest version, Firefox starting showing the error in the console. So appears to be some peculiar behavior in preact@6, preact@7 and Firefox.

I'm not very familiar with v6/7 of preact, so I may not be much help here, sorry.

@andrewiggins I did not know preact 6 was not the latest one, switching to 8 fixed the problem, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

k15a picture k15a  路  3Comments

KnisterPeter picture KnisterPeter  路  3Comments

youngwind picture youngwind  路  3Comments

rajaraodv picture rajaraodv  路  3Comments

matthewmueller picture matthewmueller  路  3Comments