I have a custom dijit that loads fine when debugAtAllCosts = true, but fails when debugAtAllCosts = false with this error:
failed loading script/dojo15root/dojo/../../widget/DatePicker.js
with error: TypeError: dojo.body() is undefined
I know that using debugAtAllCosts = true makes dojo use the XD loader which loads modules asynchronously. So normally people have problems when they go from the synchronous to asynchronous loader. What kind of bug should I be looking for when the widget loads fine with the asynchronous loader, but does not load with the synchronous loader?
I could post the code, but it is composed of a lot of different js files and other widgets that could also be the problem. So at this point I’m trying to narrow the problem by figuring out when this problem could occur.
My djConfig when the widget fails to load:
<script type="text/javascript">
var djConfig = {
parseOnLoad: true,
isDebug: true,
locale: 'en-us',
debugAtAllCosts:false,
modulePaths:{'widget':'../../widget','datepicker':'../../datepicker'}
};
</script>
My djConfig when the widget loads:
<script type="text/javascript">
var djConfig = {
parseOnLoad: true,
isDebug: true,
locale: 'en-us',
debugAtAllCosts:false,
modulePaths:{'widget':'../../widget','datepicker':'../../datepicker'}
};
</script>
Thanks in advance!
After reading about the different loader strategies, I figured my problem had to be with instantiating a dijit in some javascript code before the file had been loaded.
Turned out the offending line was here:
I fixed it by moving the instantiation into the
postCreatefunction so as to be sure the widget and all “require”s would be loaded.I’m still not 100% sure why the standard loader would exhibit this problem, because by my understanding it loads things synchronously; whereas the XD loader loads asynchronously. My guess is that during the widget lifecycle, the widget attributes get created before the widget’s “require”s are loaded. But that doesn’t explain why the XD loader would work in this situation…
If someone can explain why the XD loader works, when the standard loader fails in this situation, I would gladly accept that answer. Otherwise, I’ll accept my answer because it does fix the problem.