ember-href-to icon indicating copy to clipboard operation
ember-href-to copied to clipboard

Dont trigger element handler when it doesn't exist

Open yringler opened this issue 5 years ago • 3 comments

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.

yringler avatar Jul 23 '20 21:07 yringler

@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?

GavinJoyce avatar Jul 23 '20 21:07 GavinJoyce

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 avatar Jul 24 '20 16:07 yringler

~~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.

yringler avatar Jul 28 '20 14:07 yringler