Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #103 Html.map + blur event on DOM removal makes impossible states possible #166

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

decioferreira
Copy link
Contributor

@decioferreira decioferreira commented Mar 4, 2020

Updated SSCCE: https://ellie-app.com/8cPfM8xMj7Za1

This issue happens in chrome, and not firefox (as mentioned on #103). To see the issue on the SSCCE above:

  • press "Go to B"
  • look at the Logs
  • impossible message MsgB BlurA triggered by the blur event

More details about the problem can be found on #103.

This should also fix elm/html#119 as mentioned on #105.

@matsjoyce
Copy link

@decioferreira This PR misses the case when no Html.map is used. In that case, eventNode is the sendToMap function. A version that accounts for that is:

			var oldHandler = oldCallback.__handler;
			if (oldHandler.$ === newHandler.$)
			{
				oldCallback.__handler = newHandler;
				oldCallback.__eventNode = eventNode.__tagger ? {
					__tagger: eventNode.__tagger,
					__parent: eventNode.__parent
				} : eventNode;
				continue;
			}
			domNode.removeEventListener(key, oldCallback);

// and

	callback.__handler = initialHandler;
	callback.__eventNode = eventNode.__tagger ? { __tagger: eventNode.__tagger, __parent: eventNode.__parent } : eventNode;

	return callback;

@decioferreira
Copy link
Contributor Author

hi @matsjoyce, thank you so much for your comment. Any chance you could share an SSCCE which shows the problem that your change would allow to fix? thanks in advance

@matsjoyce
Copy link

With the following code, click on the input and then somewhere else (focus then unfocus).

module Main exposing (main)

import Html as H
import Html.Events as HE
import Browser

type alias Model = {}
type Msg = Blurred

main =
    Browser.sandbox
        { init = {}
        , update = update
        , view = view
        }

update msg model = {}

view model = H.input [HE.onBlur Blurred] []

In the console I get:

Test.elm:3005 Uncaught TypeError: currentEventNode is not a function
    at HTMLInputElement.callback (Test.elm:3005)
callback @ Test.elm:3005

Pointed out by @matsjoyce on the PR, thanks!
@decioferreira
Copy link
Contributor Author

@matsjoyce I've updated the code with your fix, thank you!

@cmditch
Copy link

cmditch commented May 3, 2022

Thanks for opening this @decioferreira. This has been affecting us as well. How have you addressed the problem in the meantime?

@lucamug
Copy link

lucamug commented May 3, 2022

@cmditch,

How have you addressed the problem in the meantime?

Some workaround seems available at #103

@thomasin
Copy link

thomasin commented Jan 6, 2023

Just a note: I experience this bug only in Safari now, not Chrome or Firefox (with a Mouse Leave event)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Impossible message type created by Html.map
5 participants