-
23 Jul 2012 7:27 PM #1
[ExtJS 4.1.1] Ext.require does not call callback if provided
[ExtJS 4.1.1] Ext.require does not call callback if provided
If I pass a callback fn to Ext.require, it never gets called. For example, Ext.require('Sjs.apps.examples.reference.Main', function() { console.log('loaded'); });
This problem appeared in 4.1.0 and is critical to the proper functioning of our environment. This is blocking us from upgrading from 4.0.7.
-
23 Jul 2012 7:45 PM #2
Works ok for me:
I tried it with ext-all.js and also dynamic loading against 4.1.1, the log fires in both cases.Code:Ext.require('Ext.panel.Panel', function(){ console.log('Foo'); });Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
24 Jul 2012 10:43 AM #3
Ok, well I'll have to do more digging and see if I can create an example to show the problem. In our environment, we define application classes that extend Ext.app.Application, and when an app is required on the page, Ext.require is called, passing the app class name and a callback. 100% of the time, the callback never gets called because of this line in Loader.js:
syncModeEnabled is always false. The callback never gets called.Code:if (syncModeEnabled) { callback.call(scope); ...
By the way, I'm using ext-dev.js. Also, the code I am using that doesn't work in 4.1.1, works fine in 4.0.5.
-
24 Jul 2012 11:06 AM #4
Interestingly, if I call Ext.syncRequire(someClass, callback), then ALL the callbacks that never got called from previous Ext.require calls suddenly get invoked. Then I get a "field is undefined" exception on Model.js.
It is difficult to create a standalone example outside of our environment, but I'll see what I can do. But something has definitely changed with the Loader since 4.0.5.
-
24 Jul 2012 2:01 PM #5
Here's a big clue:
When our main page loads, we wind up in a state where Ext.Loader.numPendingFiles == 4. The pending files turn out to be the scripts for the classes Ext.LoadMask, Ext.Ajax, Ext.data.Store and Ext.data.AbstractStore.
Coincidentally, in the Ext.Loader.loadScriptFile method, there is this code:
If I write the url to the console at this point, guess what files I see?Code:if (isFileLoaded[url]) { return Loader; }
Having that check in loadScriptFile prevents the onLoad handler from getting called. This check was not present in 4.0.5. The expectation is that the onLoad handler should always get called, even if the file is already loaded. That's not happening.Code:http://hom-bhubbard3/assets/scripts/deploy/ext-live/src/data/AbstractStore.js already loaded http://hom-bhubbard3/assets/scripts/deploy/ext-live/src/data/Store.js already loaded http://hom-bhubbard3/assets/scripts/deploy/ext-live/src/Ajax.js already loaded http://hom-bhubbard3/assets/scripts/deploy/ext-live/src/LoadMask.js already loaded
-
24 Jul 2012 3:16 PM #6
I still see the callback fired:
Code:Ext.require('Ext.panel.Panel'); Ext.onReady(function() { Ext.require('Ext.panel.Panel', function(){ console.log('loaded'); }); });Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
24 Jul 2012 3:35 PM #7
That is too simplistic of an example. Our environment loads numerous apps on the same page, and it seems in the process, somehow the require requests hit a condition whereby loadScriptFile is getting called twice for the same file.
I had to patch Loader.js with the following code to make it work. Please get this pushed into the product. This was a difficult method to override due to closure references created when ExtJS code was optimized.
Code:loadScriptFile: function(url, onLoad, onError, scope, synchronous) { if (isFileLoaded[url]) { if (synchronous) { onLoad.call(scope); } else { defer(onLoad, 10, scope); } return Loader; } ...
-
25 Jul 2012 5:11 PM #8
Further investigation reveals there is something going on that is influenced by network latency, as I wind up with anywhere from three to five classes for which loadScriptFile gets called twice. And with the fix I mentioned previously, I am now occasionally seeing numPendingFiles go negative, suggesting an onLoad callback is getting called twice. There's definitely something screwy going on, as everything just works in 4.0.5 and 4.0.7 and then everything stops working in 4.1.0.
-
25 Jul 2012 5:19 PM #9
It's almost impossible to say without seeing a test case, because:
a) We need to be able to reproduce it to figure out if/what the problem is
b) We need to be able to reproduce it so we can verify it's fixed if there is a bugEvan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
25 Jul 2012 7:23 PM #10
I understand. And it's almost impossible to build a test case to show the problem when I don't know what's causing it, especially when is seems there's a few too many variables involved. I'm providing as much information as I collect about the problem, since I figured you guys wrote the code, so maybe you are more familiar with it than I am and might glean some clue about what could be the problem. We've got a lot riding on this and time is money, so I'm doing what I can to find the cause. Do I need to go through premium support for assistance?
Wait! Looks like we don't have enough information to add this to bug database. Please follow this template bug format.


Reply With Quote
