-
Notifications
You must be signed in to change notification settings - Fork 815
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
Mailchimp popup widget pollutes global scope with require and define variables #8546
Comments
…rom global scope after using a require definition
Do you know of any scenario when this would happen? Both jQuery and jQuery UI are usually loaded in the head, while the shortcode is loaded in the body. Some caching plugins will change that, but did you run into a specific scenario where jQuery and jQuery UI were not loaded right after each other? |
…ndow.define from global scope and thus breaking mailchimp script, set window.define.amd to fool just real amd modules. Mailchimp script seem to expect usable definitions of require and define, once we remove them it breaks. Since the purpose of this commit is to fix scripts like jquery-ui that will resort to define() if define.amd is defined - it is enough to unset define.amd. This is a very ugly solution, but it works.
@jeherve I found this problem by tracking down 903897-zen. Basically as a result of installing some plugins the order of <script> tags became very unfortunate and a jquery-ui calendar broke on a woocommerce page. I agree it can be mitigated by caching plugins, but things breaking unexpectedly is a bad user experience and requires a lot of support time to track down. |
…ttic#8546 - test for updated script string.
* Fix issue #8546 - remove window.require and window.define from global scope after using a require definition * Fix issue #8546 - instead of removing window.require and window.define from global scope and thus breaking mailchimp script, set window.define.amd to fool just real amd modules. Mailchimp script seem to expect usable definitions of require and define, once we remove them it breaks. Since the purpose of this commit is to fix scripts like jquery-ui that will resort to define() if define.amd is defined - it is enough to unset define.amd. This is a very ugly solution, but it works. * Update mailchimp shortcode test to match earlier fix for issue #8546 - test for updated script string.
OMG this helped me so much, Thank you so much for that |
Steps to reproduce the issue
What I expected
window.define
andwindow.require
to be nullWhat happened instead
window.define
andwindow.require
are set variables.This is very problematic if e.g.
jquery
is defined before the widget andjquery-ui
is defined after the widget. Ifdefine()
is available, it will be used to loadjquery-ui
as you can see here:https://code.jquery.com/ui/1.12.0/jquery-ui.js
So in this case,
define
is indeed available, butjquery
was loaded in a "regular" way. It means thatjquery-ui
will always wait forjquery
to be available as a dependency and will never be loaded.A solution
Set
window.define.amd
to undefined after the mailchimp embed is loaded:Why
window.define.amd
? Because MailChimp script needsrequire
anddefine
functions to remain in the global scope, but scripts like jquery will not usedefine
ifwindow.define.amd
is undefined, so it's a win-win (an ugly one but still).A better solution
Have mailchimp fix that on their end
The text was updated successfully, but these errors were encountered: