intercom / ember-href-to

:link: A lightweight alternative to {{link-to}}
Apache License 2.0
190 stars 42 forks source link

Dont trigger element handler when it doesn't exist #130

Open yringler opened 4 years ago

yringler commented 4 years ago

In our project, sometimes navigation would end up where we didn't expect. It turns out that sometimes the href-to document handler picks up and reacts to a click event when it shouldn't. Testing that the element being responded to still exists in the DOM fixed it for us.

GavinJoyce commented 4 years ago

@yringler, thanks. Can you say more about what this is protecting against? When does the href-to document handler picks up and reacts to a click event when it shouldn't? Perhaps you could add a test?

yringler commented 4 years ago

It's picking up a click on a component which extends the ember linkto component. After the ember linkto finishes navigation, the handler from href-to is hit.

I don't have time to look into it further, unfortunately. For now we're just using my fork (I love yarn (which supports specifying a github url/branch!).

yringler commented 4 years ago

On further review, it looks like this is related to https://github.com/intercom/ember-href-to/blob/36c2fa8793a010e3abfa09f5a98d16cbb348317a/addon/href-to.js#L58. ~~We check in that method if click came from a link component, but not if it came from a component which inherits from link. I'll either switch our code to using link component directly, or update the PR~~ Edit: when I click on a link-to, by the time the handler is running the link to doesn't exist anymore (navigation already happened), and the check this.applicationInstance.lookup('-view-registry:main')[id] returns undefined.