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

Form e.preventDefault() broken in Firefox (0.8.3-0.8.13) #61

Closed
dotnetshadow opened this issue Jul 29, 2023 · 4 comments · Fixed by #62
Closed

Form e.preventDefault() broken in Firefox (0.8.3-0.8.13) #61

dotnetshadow opened this issue Jul 29, 2023 · 4 comments · Fixed by #62

Comments

@dotnetshadow
Copy link

dotnetshadow commented Jul 29, 2023

Hi there,

It seems any code such as the following in Firefox breaks.
Chrome / Edge seem ok, but Firefox doesn't work

document.getElementById('my-form').addEventListener('submit', function (e) { e.preventDefault(); alert('This doesn't get called because the page navigates away'); });
The page just navigates away without being stopped

I tried various versions of the library and v0.8.1 is the last working version
0.8.3-0.8.13 BROKEN

@dahlbyk I noticed you made some changes during 0.8.3 release anything you can think of that would stop it form working in Firefox?

I suspect an issue with this part of the code
v0.8.1...v0.8.3#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80R728

image

Any help would be much appreciated

@dahlbyk
Copy link
Collaborator

dahlbyk commented Jul 29, 2023

@dahlbyk I noticed you made some changes during 0.8.3 release anything you can think of that would stop it form working in Firefox?

Apparently #33 just doesn't work on Firefox. Here's a minimal repro and a proposed fix: https://codepen.io/dahlbyk/full/oNQQoMq.

image

In short, Firefox isn't firing submit listeners for the redispatch here:

submitValidForm = (form: HTMLFormElement, submitEvent: SubmitEvent) => {
const newEvent = new SubmitEvent('submit', submitEvent);
if (form.dispatchEvent(newEvent)) {

Using setTimeout(fn, 0) seems to allow the original submit handler to finish before dispatching at the next opportunity.

If the Pen seems to work for you I'll submit a PR.

@dahlbyk
Copy link
Collaborator

dahlbyk commented Jul 30, 2023

I'll submit a PR.

Give #62 a try?

@dotnetshadow
Copy link
Author

Thank you so much for fixing it, works great :)

@dahlbyk
Copy link
Collaborator

dahlbyk commented Aug 10, 2023

Ironically I just noticed this in https://ab.bot/ last night, prompting an upgrade. Thanks for finding it first. 😁

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 a pull request may close this issue.

2 participants