Skip to content

Toolbar introduces race condition on requireJS sites #605

Closed
@spectras

Description

@spectras

On version 1.2.1, do not know for master nor older releases. Opening an issue so other people with the same problem can find this. It turns out google was not my friend on that one.

Root cause:
In file debug_toolbar/templates/debug_toolbar/base.html (the one that gets injected into site's pages), lines 8 to 10, the code hijacks window.define and restores it later.

However, as it is a global and requireJS does aynchronous loading, a whole bunch of funny stuff can happen randomly.

Some effects:
Here is what I experienced until I eventually found out debug_toolbar was the culprit:

  • some other module gets ready and tries to call define at this very time, breaking with a define is not defined, aborting module load.
  • more fun: the main jQuery completing its loading asynchronously, registering itself as window.jQuery only to have debug toolbar call noConflict on it, before requireJS has time to grab the reference. Therefore, everything appears to load fine, except module that use jQuery will get undefined instead of jQuery.

Workaround:
As a workaround, it is possible to set JQUERY_URL to None in the settings. This forces debug_toolbar to use the main jquery and not try to load its own. However, doing so requires that the main jQuery be loaded before the toolbar kicks in so either:

  • load jQuery synchronously
  • or wrap the whole scripting part of debug_toolbar in a require(['jquery'], function(jQuery){ }) block, then wrap toolbar's script in define blocks. That's messy though, I would not recommend it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions