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

Use event.target in cases where _firstTarget has been removed from DOM #17

Merged
merged 3 commits into from
Jan 25, 2024

Conversation

sgparrish
Copy link
Contributor

I have a use case in vis-timeline where _firstTarget ends up getting removed from the DOM during a pan event. This causes the pan to stop immediately because it no longer a descendent of the hammer root element.

@josdejong
Copy link
Owner

Thanks @sgparrish .

I can imagine that document.contains(...) can be slow when you have a large document. Is there a faster way to check whether the target is still attached to the DOM? Maybe loop over all parentNodes to check if it ends up in the root element where we've attached hammer?

@josdejong
Copy link
Owner

Thanks for the update. I think this makes sense. However I'm thinking about cases like when a DOM element is rendered but does not have a parent <document>, for example when using Shadow DOM. And I think the same holds for your first approach with document.contains.

I was reading up on this StackOverflow question: https://stackoverflow.com/questions/5649534/html-element-is-attached-to-a-document

This suggests using yourElement.isConnected, which should work in Shadow DOM and IFRAME's too. What do you think about using isConnected?

On a side note: I realize I just assumed that document.contains is slow, but I actually do not know if that is the case 🤔. Anyway.

@sgparrish
Copy link
Contributor Author

Oh yeah, isConnected looks like the right solution.

Do you think I should include this as an option? I could imagine this breaks some behavior for someone.

Re: side note:
I did some brief research on document.contains after your first comment and did find a benchmark, but I think either I misinterpreted it or it was outdated. Turns out, under the hood (at least for chromium based browsers) document.contains does something similar to the function I wrote. (chromium source, 1406 it does the parentNode traversal)

@josdejong
Copy link
Owner

I think isConnected can indeed be used instead, like you do with your latest commit.

Do you think we should take care of a possible absence of the isConnected property? It is supported by all browsers except IE (which is EOF already for a long time), so, effectively propagating-hammerjs will not work on IE 11 anymore with this PR.

@josdejong
Copy link
Owner

I think isConnected can indeed be used instead, like you do with your latest commit.

Do you think we should take care of a possible absence of the isConnected property? It is supported by all browsers except IE (which is EOF already for a long time), so, effectively propagating-hammerjs will not work on IE 11 anymore with this PR.

What do you think @sgparrish ?

@sgparrish
Copy link
Contributor Author

sgparrish commented Jan 24, 2024

IE has been dead for over a year at this point. I think just bumping the major version should be sufficient to prevent any existing behavior breaking for consumers expecting propagating-hammerjs to behave in IE11 environments.

If anyones starting new development intending it to be IE11 compatible (god help them) they could be directed to an older version?

If it's actually a strong concern- I suppose the check could be modified to check typeof _firstTarget.isConnected. I think it should resolve to undefined in the IE11 case and boolean in all modern browsers. It's really tough to know, though- my windows 10 box won't even let me open IE anymore. In the IE11 case then some other operation could be done

@josdejong
Copy link
Owner

Good point. Let's not spend too much effort on keeping it working in IE11. Instead, I'll simply publish it as a major, breaking change.

Thanks for providing this fix!

@josdejong josdejong merged commit 0a76fff into josdejong:master Jan 25, 2024
1 check passed
@josdejong
Copy link
Owner

Published now in v3.0.0

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.

None yet

2 participants