getify/LABjs

$LAB.wait() executes prematurely

mklepaczewski opened this issue · 9 comments

Hello,

In Opera 9.63 (and I get reports that in IE 8 Win7 64bit also, but I wasn't able to confirm it) .wait() body is executed prematurely. Here are two test files

test.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="Mon, 26 Jul 1997 05:00:00 GMT" />
<script type="text/javascript" src="LAB.min.js"></script>
<script type="text/javascript">
    $LAB
    .script("test.js")
    .wait(function() {
        alert("This should execute after test.js");
    })
    .wait()
</script>
</head>
    <body>
       Hello 
    </body>
</html>

test.js

function pausecomp(millis) {
  var date = new Date();
  var curDate = null;
  do { curDate = new Date(); }
  while(curDate-date < millis);
}

pausecomp(10 * 1000);

alert("test.js finished execution");

Under Win7 64 bit Opera 9.63 contents of wait() is executed immediately (i.e. first "This should execute after test.js" shows up and then after several seconds "test.js finished execution"), but from my understanding it should wait till test.js finishes its execution?

In Chrome, IE 10 and FF it works as expected.

Matt

What version of LABjs are you using? Can you put this test up on a URL so I can reproduce?

Wow, I knew that You still provide support for the library but wasn't expecting so quick response! Thanks!

I'm using v2.0.3, here's the test on the web:
http://www.data-diggers.com/test/test.html

Note: It gets even bit more stranger. In Opera 9.63 if I hit Refresh the script executes as expected, but if I just load it again (type the address again without refreshing it ) the script misbahaves and wait() body is executed immediately. Maybe it's caching issue? It seems that if the script is cached control to .wait() is passed right away without waiting for script execution to finish.

It definitely shouldn't be doing what you're seeing. I find it quite bizarre. That having been said, I haven't seen or touched Opera 9 in years. All I know is that way back then, it did work. I dunno if they've broken something about their script loading mechanisms. Will take some investigation, but I'll try to see what I can figure out. Thanks for the test link.

Thanks, it will be great if You will be able to fix it.

Just level-setting expectation here: it's pretty unlikely this is a bug in LABjs, given how long LABjs has been stable (over 2 years and no valid bugs), and given the fact that LABjs used to work fine in Opera 9.x. I will certainly investigate what's going on and try to reproduce and diagnose.

If it's a bug that can be fixed in LABjs, the chances of a new release of LABjs to fix it are slim (given how minority/legacy a browser Opera 9.x is). The best you could probably expect is a suggestion on how to patch your copy of LABjs.

More likely though, it could be a newly introduced bug in a port of Opera to a newer platform, in which case that's completely the fault of the browser and may very well be nothing LABjs can do about it. At that point, you'd have to contact Opera about it, but since they have long since retired support for Opera 9.x, I'm not sure how much help they'd be.

Not trying to scare you off. I'll do my best to figure it out, as soon as I get some free time. It may be a bit. And I just wanted to warn you that the resolution may be less than desirable. But we'll see. :)

It's probably a separate issue, but I noticed something like this in IE10. I had a script that was getting loaded with .script().wait(), and if I browsed away from the page, it seemed to cause the .wait function to get triggered immediately (sometimes, depending on timing). It didn't really affect behavior, but ended up triggering an error.

I have not been able to reproduce. Please provide more information if this problem is still persistent for you, and we can re-open.

Hi,

I am also experiencing this with LABjs (v1.2.0) in IE10. Interestingly, it does not appear to have this problem in earlier versions of IE (or any other browser that I've tried so far)...

My LABjs loader code looks something like this:

$LAB.setOptions({AlwaysPreserveOrder:true})
.script([BASE_URL,'js/jquery-1.5.2.min.js'].join(''))
.script([BASE_URL,'js/jquery-ui-1.8.11.custom.min.js'].join(''))
.script([BASE_URL,'js/otherstuff1.js'].join(''))
.script([BASE_URL,'js/otherstuff2.js'].join(''))
.script([BASE_URL,'js/mainstuff.js'].join(''))
.wait(function() {
jQuery(function(){MainThing.go();});
});

The code inside the anonymous function in wait() fails with an error indicated that MainThing is not defined (which "mainstuff.js" should do).

When I look at mainstuff.js in the IE dev tools (via the Network capture) I can see that it has received the response containing the code..

However, when I try to look at mainstuff.js in the Script view (of the IE dev tools), the file appears empty...

Any ideas?

Thanks,
Tom

FYI I've implemented a simple workaround for my problem as a temporary solution. My script executes a function which checks for the definition of MainThing, if it is not there yet, it yields for 200ms and calls itself again until MainThing is defined.

I appreciate this introduces a potentially infinite loop, but without MainThing, the application is completely worthless anyway so it is an acceptable trade-off from my perspective.

// Define my namespace
if(typeof MyNameSpace=== 'undefined') {
MyNameSpace = function () { "use strict"; };
}

// Repeatedly attempt to launch the application to get around the LABjs wait() bug in IE10
MyNameSpace.go = function() {
if(typeof MainThing === "undefined") {
setTimeout(MyNameSpace.go, 200);
} else {
MainThing.go();
}
};

$LAB.setOptions({AlwaysPreserveOrder:true})
.script([BASE_URL,'js/jquery-1.5.2.min.js'].join(''))
.script([BASE_URL,'js/jquery-ui-1.8.11.custom.min.js'].join(''))
.script([BASE_URL,'js/otherstuff1.js'].join(''))
.script([BASE_URL,'js/otherstuff2.js'].join(''))
.script([BASE_URL,'js/mainstuff.js'].join(''))
.wait(function() {
jQuery(function(){MyNameSpace.go();});
});