elm / html

Use HTML in Elm!
https://package.elm-lang.org/packages/elm/html/latest/
BSD 3-Clause "New" or "Revised" License
395 stars 99 forks source link

Runtime error: TypeError: currentEventNode is undefined #214

Closed changlinli closed 4 years ago

changlinli commented 4 years ago

I'm still trying to create a reproducible minimum example since unfortunately this seems to be disappearing whenever I try to pare down my code to reproduce it. In the meanwhile I'm posting this bug in case anyone has seen this before and can answer and also so that this can serve as a search engine sign post.

In particular, this seems to arise from an onClick attribute on a div. The generated Javascript is

function _VirtualDom_makeCallback(eventNode, initialHandler)
{
    function callback(event)
    {
        var handler = callback.q;
        var result = _Json_runHelp(handler.a, event);

        if (!$elm$core$Result$isOk(result))
        {
            return;
        }

        var tag = $elm$virtual_dom$VirtualDom$toHandlerInt(handler);

        // 0 = Normal
        // 1 = MayStopPropagation
        // 2 = MayPreventDefault
        // 3 = Custom

        var value = result.a;
        var message = !tag ? value : tag < 3 ? value.a : value.message;
        var stopPropagation = tag == 1 ? value.b : tag == 3 && value.stopPropagation;
        var currentEventNode = (
            stopPropagation && event.stopPropagation(),
            (tag == 2 ? value.b : tag == 3 && value.preventDefault) && event.preventDefault(),
            eventNode
        );
        var tagger;
        var i;
        while (tagger = currentEventNode.j)
        {
            if (typeof tagger == 'function')
            {
                message = tagger(message);
            }
            else
            {
                for (var i = tagger.length; i--; )
                {
                    message = tagger[i](message);
                }
            }
            currentEventNode = currentEventNode.p;
        }
        currentEventNode(message, stopPropagation); // stopPropagation implies isSync
    }

    callback.q = initialHandler;

    return callback;
}

I'll add Elm code when I can create an SSCCE.

Perhaps this is a https://github.com/elm/virtual-dom bug?

changlinli commented 4 years ago

Turns out there was some subtle interaction with some port code that was touching the DOM in a way that then made it inconsistent with the virtual dom. Closing out as a result.