#1319 closed bug (fixed)
$().ready() sometimes fires too soon on Safari/Win
Reported by: | dmethvin | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | event | Version: | 1.3.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
(It may also fire too soon on Safari/Mac but I can't test that.)
Go to this page in Safari/Win:
http://methvin.com/jquery/splitter/vsplitter.html
Occasionally, it will not initialize properly--the right pane is too short by the width of a non-existent scroll bar. You may need to reload it repeatedly to see the problem.
I think this is due to one or more document properties being invalid at that point. If I remove the special-case Safari handling in jQuery's ready() method and let it drop into the onload case instead, the problem goes away.
According to this page, Safari fires onload *very* early, before the page has displayed, so that code is most likely overkill anyway.
Attachments (6)
Change History (26)
comment:1 Changed 16 years ago by
Component: | ajax → event |
---|---|
Milestone: | 1.1.3 → 1.1.4 |
Version: | 1.1.2 → 1.1.3 |
comment:2 Changed 15 years ago by
I've noticed the same thing happening on my site:
http://thoughts.kuzemchak.net/
The archives area (under the main nav) should hide by default using $(function() {...}), but in Safari 3 it will still show unless the page is refreshed.
comment:3 Changed 15 years ago by
Happened at http://methvin.com/jquery/splitter/vsplitter.html in only one of nearly 50 calls, but really appears.
comment:4 Changed 15 years ago by
Milestone: | 1.1.4 → 1.2.1 |
---|---|
Resolution: | → worksforme |
Status: | new → closed |
Version: | 1.1.3 → 1.2 |
Unable to duplicate.
comment:5 Changed 15 years ago by
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
I can make this happen almost every time at http://methvin.com/jquery/splitter/vsplitter.html -- Safari 3.0.4, Mac OS 10.5
I also have the problem where hide() doesn't work in a $(document).ready() context. I must use css({display: 'none'}) instead.
comment:6 Changed 15 years ago by
So, a workaround is to use $(window).bind("load", ...) instead of $(document).ready() on Safari.
I've still not figured out why this bug happens on some pages but not on others, alas.
Changed 15 years ago by
Attachment: | jquery_test.html added |
---|
test case (slightly modified so can download)
comment:8 follow-up: 9 Changed 15 years ago by
Milestone: | 1.2.1 → 1.2.2 |
---|
It seems to still happen in the current SVN. I modified the test case so you can download it. By editing the jquery_test.html file you can see there are two lines that are:
window.onload = (function () { $().ready(function ()
By commenting one and and one in, the problem shows itself.
comment:9 Changed 15 years ago by
Let me try those two lines again:
window.onload = (function () {
$().ready(function () {
comment:10 follow-up: 11 Changed 15 years ago by
I can also confirm this happens in Safari 3 win. However, I don't think we can rely on the window.onload event to always act as it currently does in Safari 3. The article you link to specifies that this "bug" is marked fixed in their bug tracker. Not sure what fixed means but I imagine it isn't want we want. The webkit nightlies support the DOMContentLoaded event but until then we will need to figure out anther hack for Safari.
comment:11 Changed 15 years ago by
Replying to brandon:
I can also confirm this happens in Safari 3 win.
I meant to say: I can also confirm this happens in the latest Safari 3 win and mac.
comment:12 Changed 15 years ago by
I'm not positive yet, this appears to be a problem with an external css file not being loaded and applied before the ready event fires. I'm guessing that is what causes this racing condition where it sometimes works and sometimes doesn't.
So I put together a simplified test case using php instead of a css file and a 1 second pause when loading it. There is a problem where the width is returning 'auto' at the ready event then '100px' at the onload event. I suspect this might be the problem. Opera is returning '0' at the ready event (but it works in the initial test case). FF and IE both return '100px' for both events.
comment:13 Changed 15 years ago by
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Fixed in [4245]. There are many possible scenarios and edge cases to this kind of bug. The current fix seems fairly solid but until it gets tested in the beta we can't be sure. Please reopen the bug (if) with any problems you see ASAP.
comment:14 Changed 14 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
I am now noticing this problem again. Safari v3.2.1 windows. Issue is that Ready event fires before css files have loaded in safari. Simple / Easy work around is to declare your css files in the document head BEFORE the script files. If CSS files are after script files then the event fires before the css has loaded.
comment:15 Changed 14 years ago by
I've updated the entry for .ready() to emphasize that css needs to all be loaded before script, especially on Safari.
comment:16 Changed 14 years ago by
I can confirm this is a problem in Safari 3 for Mac, and Google Chrome (essentially all new Webkit based browsers).
Putting the CSS above the scripts does work, but it seems strange this hasn't been fixed yet - or is this a Webkit bug?
It seems fairly obvious that the whole point of the ready function is to start things at the point that all the essentials have loaded, so (if possible) a fix should be in order.
Changed 14 years ago by
Attachment: | jquery-example.htm added |
---|
comment:17 Changed 14 years ago by
I don't think this has anything to do with CSS. I've attached a very simple example that shows that setting designMode inside jQuery's ready() function fails in Safari Win 4.0 (530.17) and Chrome 2.0.172.30.
comment:19 Changed 13 years ago by
Milestone: | 1.2.2 → 1.4 |
---|---|
Resolution: | → fixed |
Status: | reopened → closed |
Version: | 1.2 → 1.3.2 |
An additional check was added to 1.4 to make sure that the body is available, at least, before the ready event will fire. This should resolve the issue.
comment:20 Changed 12 years ago by
I'm getting similar issue in Safari with images. Shouldn't ready() be called after browser fetched images on a page? At least It works fine in other browsers. But in Safari it only works on full page reload (Shift+Reload).
comment:21 Changed 12 years ago by
No, ready is NOT fired after the browser downloads images on a page, ready is fired when the dom is manipulable but before the images have downloaded.
I have not been able to duplicate this, even with your test page. Are you still able to duplicate it?