wp-polyfill-importmap causes duplicate DOMContentLoaded trigger, 2024 theme
-
Hi,
I noticed when using cf7 on sites running the 2024 theme, there is a bug that causes duplicate feedback and potentially double submission, breaking captchas and lots of other extensions. This is caused by wp-polyfill-importmap.js triggering multiple DOMContentLoaded events when the browser used is missing support for importmaps.
I have tested this with all plugins and caching disabled, running only 2024 theme and cf7.
This happening on safari mobile as well as safari for MacBook and probably some other browsers.Here is a trace of what’s happening, ignore the unrelated event-manager-scripts.js errors:
[Log] Trace FA (wp-polyfill-importmap.min.js:597) (anonymous function) (wp-polyfill-importmap.min.js:602) asyncFunctionResume (anonymous function) promiseReactionJobWithoutPromise [Log] Trace (anonymous function) (index.js:2) forEach m (index.js:2) (anonymous function) (index.js:2:3595) forEach (anonymous function) (index.js:2:3579) [Error] ReferenceError: Can't find variable: EM (anonymous function) (event-manager-scripts.js:9) [Log] Trace FA (wp-polyfill-importmap.min.js:597) promiseReactionJob [Log] Trace (anonymous function) (index.js:2) forEach m (index.js:2) (anonymous function) (index.js:2:3595) forEach (anonymous function) (index.js:2:3579) dispatchEvent FA (wp-polyfill-importmap.min.js:598) promiseReactionJob [Error] ReferenceError: Can't find variable: EM (anonymous function) (event-manager-scripts.js:9) dispatchEvent FA (wp-polyfill-importmap.min.js:598) promiseReactionJob [Log] Trace FA (wp-polyfill-importmap.min.js:597) (anonymous function) (wp-polyfill-importmap.min.js:602) asyncFunctionResume (anonymous function) promiseReactionJobWithoutPromise
I was able to patch this locally by adding a basic check to the DOMContentLoaded handler in contact-form-7/includes/js/index.js file to only run once:
document.addEventListener("DOMContentLoaded",(e=>{ window.mCalled = window.mCalled || false; if(window.mCalled) return; window.mCalled = true; console.log('wpcf7 dom content loaded');var t;if("undefined"!=typeof wpcf7)if(void 0!==wpcf7.api)...
- You must be logged in to reply to this topic.