Tag Archives: Unable to preventDefault inside passive event listener due to target being treated as pas…

Mui Error:Unable to preventDefault inside passive event listener due to target being treated as pas…

problem description : when you click the return button, the following errors appear in the console each time:

mui.min.js:13 Unable to preventDefault inside passive event listener due to target being treated as passive.

solutions :

Locate the error line of mui.min.js, and find that the error code is a.preventdefault(), so comment out a.preventdefault() in mui.min.js, and the problem is solved

problem analysis :

What functions does the preventdefault() function implement?Is there any impact on the specific function of annotation

The preventdefault () method prevents elements from default behavior (for example, preventing the submission of forms when the submit button is clicked). For example, you can use event. Preventdefault() to prevent tag a from jumping

Because the browser can’t know in advance whether an event handler will call preventdefault (), it needs to wait until the event handler is executed before it can execute the default behavior. However, the execution of the event handler is time-consuming, which will cause the page to jam. That is to say, when the browser waits for the default behavior of the event to be executed, Most of the time it’s just waiting for nothing

If the web developer can tell the browser in advance that “ I don’t call the preventdefault function to prevent the event behavior “, then the browser can quickly generate events and improve the page performance. The proposal of passive event listeners solves this problem

In my project, I successfully solved the problem of console error reporting by commenting out preventdefault(), and I haven’t found any effect on other functions yet