event.preventDefault() is not respected when called in microtask
Categories
(Core :: DOM: Events, defect)
Tracking
()
People
(Reporter: nick.gard.dev, Assigned: smaug)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:126.0) Gecko/20100101 Firefox/126.0
Steps to reproduce:
There is a minimal test case on this pen: https://codepen.io/NickGard/pen/mdgLoZv?editors=1011
The code is:
<input id="X" is="dumb-thing">
<script>
X.addEventListener("beforeinput", (e) => {
console.log("beforeinput");
// when called here, preventDefault() correctly prevents "input" event from dispatching
// event.preventDefault();
queueMicrotask(() => {
// this is too late to call preventDefault() in Firefox.
// Safari and Chrome still prevent the "input" event from dispatching when called here
event.preventDefault();
});
});
X.addEventListener("input", (e) => {
console.log("input");
});
</script>
Actual results:
The "input" event handler is still triggered, logging "input" in the console.
Expected results:
The "input" event handler should not have been triggered.
Comment 1•2 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::DOM: Events' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
| Assignee | ||
Comment 2•2 years ago
|
||
I think the issue is this https://searchfox.org/mozilla-central/rev/d23849dd6d83edbe681d3b4828700256ea34a654/dom/events/EventListenerManager.cpp#1302
We should remove that.
Testing a bit
| Reporter | ||
Comment 3•2 years ago
|
||
After exploring this a bit more with other events' default behaviors, all of the ones I've tested are correctly prevented from occurring when event.preventDefault() is called in a microtask. For instance, the following code correctly stops characters from being entered into the input and precludes the "beforeinput" and "input" events from dispatching.
<input id="X">
<script>
X.addEventListener('keydown', event => {
queueMicrotask(() => {
event.preventDefault();
});
});
</script>
It seems that "beforeinput" is the only one that doesn't work in a microtask.
| Assignee | ||
Comment 4•2 years ago
|
||
Right, because I assume Gecko dispatches beforeinput inside another (C++) event listener.
| Assignee | ||
Comment 5•2 years ago
•
|
||
Confirmed, it is about https://searchfox.org/mozilla-central/rev/d23849dd6d83edbe681d3b4828700256ea34a654/dom/events/EventListenerManager.cpp#1302
Pushing to try to see what removing that legacy code breaks.
https://treeherder.mozilla.org/jobs?repo=try&revision=2178e650959eae709ef532c99c85d36e02382485
| Assignee | ||
Updated•2 years ago
|
| Assignee | ||
Comment 6•2 years ago
|
||
Updated•2 years ago
|
Backed out for causing xpcshell failures on test_ext_scripting_contentScripts.js
Comment 10•2 years ago
|
||
| bugherder | ||
Comment 11•2 years ago
|
||
Given bug 1893226, should we back this out until we can sort that regression out?
Comment 12•2 years ago
|
||
Backed out for breaking handful of things on slack
Backout link: https://hg.mozilla.org/mozilla-central/rev/2d59d3cfc93fa569342ae78098d774b23b75c810
| Assignee | ||
Updated•2 years ago
|
Comment 13•2 years ago
|
||
There is an r+ patch which didn't land and no activity in this bug for 2 weeks.
:smaug, could you have a look please?
If you still have some work to do, you can add an action "Plan Changes" in Phabricator.
For more information, please visit BugBot documentation.
| Assignee | ||
Updated•2 years ago
|
Updated•2 years ago
|
| Reporter | ||
Comment 14•2 years ago
|
||
Has there been any progress on fixing this in a way that doesn't cause a regression like the one in Slack?
| Assignee | ||
Comment 15•2 years ago
|
||
I've been rather busy with other things, but this is very high up in my todo list.
Comment 16•8 months ago
|
||
Is there any update on fixing this? This has broken oninput state modifications in Svelte 5 for us. Compare https://svelte.dev/playground/bf28bf223e4746a199f15ca80385487d?version=5.39.2 in Firefox vs. Chrome or Edge.
Description
•