Closed
Bug 111765
Opened 23 years ago
Closed 23 years ago
alternate style sheet not correctly inserted in document.styleSheets collection
Categories
(Core :: DOM: CSS Object Model, defect)
Core
DOM: CSS Object Model
Tracking
()
People
(Reporter: martin.honnen, Assigned: jst)
Details
Attachments
(2 files)
When I include an alternate style sheet with
<link rel="alternate stylesheet"
and then
document.write(document.styleSheets.length)
it shows 0 instead of 1.
Also
document.styleSheets[0]
is
null
while the page load. If I check back after the page is loaded then the length is
still 0 but suddenly the document.styleSheets[0] is a style sheet which is
scriptable (can be enabled and disabled).
I would expect alternate style sheets to show up in document.styleSheets while
the page load and the length property should be correct.
Here is a test page
<html>
<head>
<title>
style sheet test
</title>
<link rel="alternate stylesheet" title="green" type="text/css"
href="test20011121.css" />
<script type="text/javascript">
function output (text) {
document.body.appendChild(document.createTextNode(text));
document.body.appendChild(document.createElement('br'));
}
function checkStyleSheets() {
output('Loaded:');
output('document.styleSheets.length: ' + document.styleSheets.length);
output('document.styleSheets[0]: ' + document.styleSheets[0]);
output('document.styleSheets[0].disabled: ' + document.styleSheets[0].disabled);
}
</script>
</head>
<body onload="checkStyleSheets();">
<input type="button"
value="toggle style sheet"
onclick="document.styleSheets[0].disabled =
!document.styleSheets[0].disabled; checkStyleSheets();"
/>
<br />
<script type="text/javascript">
document.write('Loading: <br \/>');
document.write('document.styleSheets.length: ' + document.styleSheets.length +
'<br \/>');
document.write('document.styleSheets[0]: ' + document.styleSheets[0] + '<br \/>');
document.write('document.styleSheets[0].disabled: ' +
document.styleSheets[0].disabled + '<br \/>');
</script>
</body>
</html>
where the css simply contains
body { color: green; }
Reporter | ||
Comment 1•23 years ago
|
||
Reporter | ||
Comment 2•23 years ago
|
||
Comment 4•23 years ago
|
||
As far as I can tell, the problem is the following:
1) We defer alternate sheet loads. So when we create the nsDOMStyleSheetList
and it calls GetNumberOfStyleSheets the first time it gets 0.
2) The stylesheet list caches the 0 and only updates it if the StyleSheetAdded
callback is called.
This callback is never called if all the pending sheets are alternate sheets.
Worse, yet, if the remaining sheets are not all alternates there will be only
_one_ call to StyleSheetAdded, since the CSS loader will only set notification
to true on the last pending sheet. See
http://lxr.mozilla.org/seamonkey/source/content/html/style/src/nsCSSLoader.cpp#798
There is no real explanation for why we do it that way and I'm not sure what the
performance (or correctness) impact would be of notifying on all sheets here.
ccing pierre.
Assignee | ||
Comment 5•23 years ago
|
||
Anyone wanna fix this, or should I Future this bug?
Comment 6•23 years ago
|
||
Marking as dup of the original bug. Will attach a link to the testcase in that bug.
*** This bug has been marked as a duplicate of 47734 ***
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•