Open edkv opened 4 years ago
got similar issue:
I'm having run time exception in my elm app. I was not yet able to fully reproduce this in Ellie but I have a show case of that wrong message is dispatched: https://ellie-app.com/8Ld3MTGhzQba1
first page with input, when you submit it by pressing Enter while in it you navigate to second page.
Open a Debug/Console/Log and you will see Page 2 update function receive Blur event from input on Page 1
also it will execute last statement in update case for Page 2
Example
Explanation
Button
state and a button is shown in the view.Image
state. A random image is rendered in the view with aload
event listener attached that should sendImageMsg ImageLoaded
msg once the image is loaded.Browser.Events.onAnimationFrame
comes toupdate
which allows to detect that the image was rendered and started to load. The program is then transitioned to theBlank
state. Theimg
element is destroyed and an empty view is shown. The image that was requested by theimg
element is still not loaded though - the request is not finished yet.Blank
state) the image is loaded by the browser, and at this point we should receive theImageMsg ImageLoaded
msg. But if you look at the console, you'd see that we gotBlankMsg ImageLoaded
instead - which is totally wrong sinceImageLoaded
is of typeImageMsg
and can't be attached to theBlankMsg
variant of theMsg
type!Furthermore, when compiled with the
--optimize
flag, this behavior can result into potentially dangerous and hard-to-debug issues because a wrong branch of theupdate
function can be called causing some totally unrelated code to be executed. If you try the example above with the--optimize
flag, the( BlankMsg Reload, Blank ) ->
branch will be called and the page will reload. I assume this is becauseImageLoaded
andReload
are both the second variant of their types, and since the type info is removed when compiled with--optimize
, they are found by their index.