Skip to content

Undefine "define.amd" instead of "define", to allow other RequireJS modules to be loaded #746

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

Merged
merged 3 commits into from
Jul 21, 2016

Conversation

peap
Copy link
Contributor

@peap peap commented Sep 2, 2015

By undefining the entire window.define, issue #591 successfully prevents DDT's jQuery from registering itself with RequireJS under the "jquery" name. However, it also randomly prevents other RequireJS modules that are loading asynchronously from registering themselves via window.define(), since it's temporarily undefined.

This patch prevents jQuery from registering itself by unsetting window.define.amd, rather than window.define. As shown in #591, jQuery checks for a truthy amd property of window.define before registering itself, so this patch still accomplishes the goal of #591. Since window.define is still a function, however, other modules will still be able to register with define().

Eric Petersen added 2 commits September 2, 2015 12:16
When we undefine the entire window.define, modules loaded asynchronously
can randomly fail to register themselves. However, jQuery 2+ checks for
window.define.amd before registering itself as an AMD module, not just
window.define. So, by unsetting window.define.amd instead of
window.define, we don't break define() for other modules and we still
prevent the page-global jQuery from registering itself as an AMD module,
which was the ultimate goal of django-commons#591.
@aaugustin
Copy link
Contributor

I don't want to have anything to do with this hack again, but this looks like an improvement.

@peap
Copy link
Contributor Author

peap commented Sep 3, 2015

Thanks, @aaugustin.

Is there someone else who could look at it, and/or anything I can do to help this along?

@tim-schilling
Copy link
Member

tim-schilling commented Sep 3, 2015 via email

@aaugustin
Copy link
Contributor

Oh well let's merge it, we'll see what happens...

@aaugustin aaugustin merged commit 84ada4c into django-commons:master Jul 21, 2016
ryneeverett pushed a commit to ryneeverett/django-debug-toolbar that referenced this pull request Oct 2, 2016
Undefine "define.amd" instead of "define", to allow other RequireJS modules to be loaded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants