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

Issue with CustomEvent guard in input.ts onInput #227

Closed
simshaun opened this issue Aug 7, 2024 · 4 comments
Closed

Issue with CustomEvent guard in input.ts onInput #227

simshaun opened this issue Aug 7, 2024 · 4 comments

Comments

@simshaun
Copy link

simshaun commented Aug 7, 2024

Hi,

I'm switching from inputmask to maska to save some kb and I'm having trouble getting maska working.

On my input element, input events are always instanceof CustomEvent for some reason. Devtools doesn't show any listeners bound to the input. I have breaks on subtree modifications on the element's parent and that's showing nothing. I've tried disabling all browser extensions.. I've been at this for hours and I'm at a loss.

I tried cloning maska and running the dev server and it works fine there. So, obviously we've got something affecting the input event somewhere on our site.

Anyway.....

In maska's onInput handler, there is a guard at the beginning:
if (e instanceof CustomEvent && e.type === 'input') { return }

I presume this is to prevent infinite recursion when the setValue method dispatches its own input event on the element. I think it would be a good idea to check e.isTrusted. It tells if the event was initiated by the browser. The condition would change to this:
if (e instanceof CustomEvent && e.type === 'input' && !e.isTrusted) { return }

It seems safer and has the benefit of fixing my issue. :D

Thoughts?

@simshaun
Copy link
Author

simshaun commented Aug 7, 2024

Of course I would find the culprit after creating an issue.

An old polyfill library (that I'm removing) called viewport-units-buggyfill is messing with CustomEvent.

My question about adding e.isTrusted still stands though.

@beholdr
Copy link
Owner

beholdr commented Aug 21, 2024

Sorry for the delay. Aren't CustomEvents always not trusted? Or are you referring to the case where some library might mutate global events and create a CustomEvent that is also isTrusted?

@simshaun
Copy link
Author

Sorry for the delay. Aren't CustomEvents always not trusted?

One would think.

I don't fully understand why their CustomEvent polyfill is affecting the input event. It's causing a form field's input event to be both instanceof CustomEvent and isTrusted (true).

I think it has something to do with them inheriting the base Event's prototype: https://github.com/rodneyrehm/viewport-units-buggyfill/blob/master/viewport-units-buggyfill.js#L95

Anyway, this is really an edge case and probably won't affect 99% of people.

beholdr added a commit that referenced this issue Aug 23, 2024
@beholdr
Copy link
Owner

beholdr commented Aug 23, 2024

Okay, should work in 3.0.1. Please check.

@beholdr beholdr closed this as completed Aug 23, 2024
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

No branches or pull requests

2 participants