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

Invalid elements allow trigger inline submit handlers and preact submit handlers #40

Closed
enjoythelive1 opened this issue Jul 28, 2021 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@enjoythelive1
Copy link
Contributor

The issue is that these listeners are registered before the polyfill has time to register its own listener to stop the propagation of the submit event.

Here I include 3 reproductions:

@calebdwilliams
Copy link
Owner

This is partially resolved in element-internals-polyfill@0.1.43. I'm afraid I don't know enough about how Preact handles the onSubmit event to know how to get around that particular issue.

@enjoythelive1, would you have any idea how to access that callback function (or know anyone who might)? I'm guessing it's in Preact's internals and we might be out of luck there.

@calebdwilliams calebdwilliams added bug Something isn't working help wanted Extra attention is needed labels Jul 30, 2021
@enjoythelive1
Copy link
Contributor Author

I think it has to do with how the vdom renders the components. The listeners to the form are attached before the polyfill can attach them, because the custom elements are instantiated after the form was instantiated with its own properties.

I think we need to catch the event before the target phase of it ('using capture'). Maybe a listener with useCapture=true at the root node of where the form is located. Having that one listener would intercept all submit events and be able to stop propagation ASAP. Even before the target fase, and that would also simplify the logic you used to store all the inline listeners of forms.

I would implement it my self, but I do't know my way around your test suite.

@calebdwilliams
Copy link
Owner

Yeah, that's exactly it. It looks like I'll have to patch document.createElement to get this to work properly (working example here). I'm not entirely sure I like this approach, but I'm still thinking about it.

@sipris
Copy link
Contributor

sipris commented Sep 12, 2022

This issue is still a thing. Run this example (before fix) in Safari or overwrite the function isElementInternalsSupported.

function isElementInternalsSupported() { return false; }

This example shows that the submit event handlers added to the form programmatically can submit data even if the form is invalid.

To prevent this, we should listen to the submit events on the submit button and prevent default handling. This example (with fix) does precisely this. PR is coming.

sipris added a commit to sipris/element-internals-polyfill that referenced this issue Sep 12, 2022
Listen for submit events on the closest submit button
and if the form is invalid prevent the default handling.
@sipris sipris mentioned this issue Sep 12, 2022
calebdwilliams pushed a commit that referenced this issue Sep 15, 2022
Listen for submit events on the closest submit button
and if the form is invalid prevent the default handling.
@calebdwilliams
Copy link
Owner

Should be fixed in element-internals-polyfill@1.1.13. Thanks @sipris!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants