After the recent update I’m getting the following in my error console on all pages. This occurs whether there is a form on the page or not, with all caching and minification disabled.
I am also running into this on a development site with 2.5.9.1 (also happened with 2.5.9 and 2.5.8). | Contact (on this page the form does not display). We have disabled minification of CSS+JS, turned off deferring or delaying JS scripts in WP-Rocket, etc.
The console errors are:
conditional_logic.min.js:1 Uncaught TypeError: gform.addAction is not a function
at conditional_logic.min.js:1
(index):850 Uncaught TypeError: gform.initializeOnLoaded is not a function
at HTMLDocument. ((index):850)
(index):855 Uncaught TypeError: gform.initializeOnLoaded is not a function
at HTMLDocument. ((index):855)
Viewing the page source code I found the theme or another plugin is wrapping the form scripts in DOMContentLoaded event listners, probably using an approach like this: Make Gravity Forms' JavaScript load in the footer
That code isn’t compatible with Gravity Forms 2.5+; the scripts are already deferred and wrapped in custom event listeners so the custom code used to implement the DOMContentLoaded change needs to be removed.
@martym the page is showing cached files for both the page and for many of the javascript assets being loaded. These are showing as powered by WP Super Cache and Autoptimize. Please Reference: Handling Page Caching & Minification and ensure you’re not getting served cached pages after making such changes.
I have tested with all caching and optimization off and the issue still persists. I’ll investigate down that road further and see if I can make progress.
Is there a comprehensive list of files to avoid caching/minifying for current version of GF? I think we had all the right rules in place previously but perhaps with recent GF updates the lists need to be updated. Thanks again for your help!
I am seeing a similar issue getting caught in our bug reporter (Sentry). It seems to be happening primarily with mobile browsers on mobile devices globally.
GF is loading external scripts like gravityforms.min.js and conditonal_logic.js with the “defer” attribute. But there is an inline script calling gform.initializeOnLoaded and conditoinal_logic is calling gform.addAction.
I’m not a JS master, but from what have found this does not seem to be a good implementation – the inline JS is executed before the deferred scripts have a chance to load? seems like it should have some sort of wrapper to defer execution of the inline scripts until after all the deferred external scripts have been loaded.
Again, I’m seeing this mostly with mobile devices (reporting as Chrome 90+) on international networks – doesn’t happen on desktops, or on my devices. Which makes me wonder if the connection is slow enough in some places (or not using http/2) to cause the deferred scripts to load in a different order.
That function should be defined in an inline script located in the page header before any of the form js files are included. If that inline script is missing it indicates there is a theme or plugin conflict which you can test for using the steps here: https://docs.gravityforms.com/testing-for-a-themeplugin-conflict/
I found a solution to prevent this error from happening.
I use wpDataTables shortcodes on my website so Gravity Forms scripts are registered and enqueued after the execution of localize_hook_vars.
I created a must-use plugin to call the gform_force_hooks_js_output filter to force printing JS in the page header: