Internet Explorer(at least 6-8, I've not tested it with 9) ignores stylesheets injecting dynamically via dom, when the @import statement is used.
IE has it's own function to add stylesheets to its import collection(http://msdn.microsoft.com/en-us/library/ms531193%28VS.85%29.aspx).
Here is a simple example which won't work(copied from this issue: http://stackoverflow.com/questions/3237775/adding-import-statement-in-a-...):

var string = '@import url(test.css)';
var style = document.createElement('style');
if (style.styleSheet) { // IE
    style.styleSheet.cssText = string;
} else {
    var cssText = document.createTextNode(string);
    style.appendChild(cssText);
}
document.getElementsByTagName('head')[0].appendChild(style);

It would only work this way:

 document.styleSheets[0].addImport("test.css");

and of course this works only for internet explorer, other browsers will throw an error...

This could cause problems in drupal, when a module has multi step forms, each step is loaded via ajax and one of those steps uses a javascript functions with dependencies on css files(for example the jquery ui widgets). But I'm sure there are other issues...

CommentFileSizeAuthor
#125 ie8-linkit-lazy-load-css.png12.27 KBmiroslavbanov
#121 1071818-121.patch6.37 KBgielfeldt
#119 1071818-119.patch6.37 KBgielfeldt
#118 1071818-118-test-module-do-not-test.patch3.15 KBkristofferwiklund
#115 1071818-114-test-module-do-not-test.patch3.22 KBstar-szr
#113 1071818-113.patch6.38 KBgielfeldt
#103 1071818-103-tests.patch3.32 KBstar-szr
#103 1071818-103.patch6.38 KBstar-szr
#98 core-js-IE-addimport-1071818-98.patch6.85 KBnod_
#91 interdiff.txt2.27 KBstar-szr
#91 1071818-91.patch6.83 KBstar-szr
#91 1071818-91-tests.patch3.73 KBstar-szr
#84 core-js-IE-addimport-1071818-84.patch5.52 KBlliss
#77 core-js-IE-addimport-1071818-77.patch5.26 KBnod_
#75 core-js-IE-addimport-1071818-75.patch3.1 KBNROTC_Webmaster
#75 core-js-IE-interdiff.txt1.8 KBNROTC_Webmaster
#56 drupal8.ajax-css-ie.56.patch2.72 KBsun
#55 core-js-IE-addimport-1071818-55.patch2.79 KBnod_
#52 core-js-IE-addimport-1071818-52.patch2.81 KBJeremyFrench
#50 core-js-IE-addimport-1071818-49.patch2.81 KBJeremyFrench
#49 core-js-IE-addimport-1071818-49.txt2.81 KBJeremyFrench
#46 core-js-IE-addimport-1071818-45.patch2.78 KBnod_
#43 core-js-IE-addimport-1071818-43.patch2.78 KBnod_
#39 after_patching_1071818_39.jpg25.62 KBanthbel
#39 before_patching_1071818_39.jpg23.84 KBanthbel
#38 test_1071818.tar_.gz1.16 KBanthbel
#36 1071818-36.patch2.1 KBxjm
#36 interdiff.txt318 bytesxjm
#33 1071818-33.patch2.09 KBxjm
#33 interdiff.txt654 bytesxjm
#32 lazy-loading-css-ie-1071818-32.patch2.08 KBanthbel
#30 lazy-loading-css-ie-1071818-30.patch2.08 KBanthbel
#23 lazy-loading-css-ie-1071818-22.patch2.05 KBJeremyFrench
#22 lazy-loading-css-ie-1071818-22.txt2.05 KBJeremyFrench
#18 lazy-loading-css-ie-1071818-18.patch2.04 KBreglogge
#15 lazy-loading-css-ie-1071818-15.patch7.37 KBreglogge
#12 1071818-lazy-loading-css-ie.patch2 KBJeremyFrench
#11 test_1071818.tar_.gz1.16 KBJeremyFrench

Comments

rfay’s picture

Wow, nice work on the diagnosis. Subscribing.

fago’s picture

Title: IE: Ajax lazy load CSS » Lazy-loading CSS fails in IE
Priority: Normal » Major

This could cause problems in drupal, when a module has multi step forms, each step is loaded via ajax and one of those steps uses a javascript functions with dependencies on css files(for example the jquery ui widgets). But I'm sure there are other issues...

I'd say it's generally troublesome if the ajax system needs to add-in additional CSS via ajax_render(). We ran into this issue with the Rules UI as it caused the data-selection autocomplete to fail in IE.

droplet’s picture

Subscribing

sun’s picture

amitaibu’s picture

Subscribing

sepgil’s picture

I tried to fix this issue, but unfortunately its way more complicated than I thought.
As far as I know the @import statemant are used in drupal to bypass the limitation of 31 stylesheets. But as far as I've found out, the only way to avoid this problem is to import stylesheets inside other stylesheets. So what drupal needs is some sort of stylesheet rendering function which create stylesheets, that import stylesheets.

sun’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7
Bojhan.core’s picture

@fago how did you fix this? I am sure there are other modules that fix this now too?

JeremyFrench’s picture

This also affects IE9

JeremyFrench’s picture

Looking at this issue, I think an approach to take would be to create a new 'add_styles' ajax command. Which runs either appends the style or runs .addImport("test.css"); on any import declarations if that function exists.

We can then replace the $extra_commands[] = ajax_command_prepend('head', $styles); with that command.

If someone agrees with this general approach I'll see if I can get something working.

JeremyFrench’s picture

StatusFileSize
new1.16 KB

I have attached a module which serves as a test harness for this issue.

JeremyFrench’s picture

Status: Active » Needs review
StatusFileSize
new2 KB

Patch added. It creates a new add_css command which will add css to the head and then use addImport on any import statements in the css that was added if the function exists.

I've tested using the test case I added on ie6-9 and it seems to work but further testing would be appreciated.

xjm’s picture

Status: Needs review » Needs work
Issue tags: +Novice

Thanks for the patch! Here are a couple really minor notes on code style:

+++ b/includes/ajax.incundefined
@@ -1204,3 +1204,24 @@ function ajax_command_restripe($selector) {
+* This method will add css via ajax in a cross browser compatible way.

Minor point, but we probably want "cross-browser" hyphenated.

+++ b/includes/ajax.incundefined
@@ -1204,3 +1204,24 @@ function ajax_command_restripe($selector) {
+* This command is implemented by Drupal.ajax.prototype.commands.add_css()
+* defined in misc/ajax.js.

Can we add an @see to ajax.js at the end of the docblock?

+++ b/includes/ajax.incundefined
@@ -1204,3 +1204,24 @@ function ajax_command_restripe($selector) {
+*

There's an extra blank line here (which we'll want to keep if we add that @see after it.)

+++ b/misc/ajax.jsundefined
@@ -616,7 +616,25 @@ Drupal.ajax.prototype.commands = {
+  ¶

Trailing whitespace.

Also, note that the Drupal 8.x patch will need to be rerolled, because the core directory structure for Drupal 8 has now changed. (For more information, see #22336: Move all core Drupal files under a /core folder to improve usability and upgrades). When the patch has been rerolled, please set the issue back to "Needs Review."

Tagging as novice for the task of rerolling the Drupal 8.x patch with the cleanup described above.

If you need help rerolling this patch, you can come to core office hours or ask in #drupal-gitsupport on IRC.

reglogge’s picture

Assigned: Unassigned » reglogge

assigning this to me for a reroll

reglogge’s picture

Assigned: reglogge » Unassigned
Status: Needs work » Needs review
StatusFileSize
new7.37 KB

Rerolled with the suggestions from #13 and some additional path changes in code comment blocks.

xjm’s picture

Assigned: Unassigned » xjm
Status: Needs review » Needs work

Thanks @reglogge!

Nice catch on the path corrections. However, since those don't specifically target this bug, we should open a separate (documentation) issue for them and roll a separate patch. See: http://webchick.net/please-stop-eating-baby-kittens

tstoeckler’s picture

+++ b/core/misc/ajax.js
@@ -616,6 +616,23 @@ Drupal.ajax.prototype.commands = {
+   * Use the proprietary addImport method if available as browsers which
+   * support that method ignore @import statements in dynamically added
+   * stylesheets.

This wraps early, i.e. before 80 chars.

28 days to next Drupal core point release.

reglogge’s picture

StatusFileSize
new2.04 KB

New patch with a fix for #17 and removing the path corrections.

reglogge’s picture

Status: Needs work » Needs review

bot...

xjm’s picture

Status: Needs review » Needs work
+++ b/core/includes/ajax.incundefined
@@ -1204,3 +1204,25 @@ function ajax_command_restripe($selector) {
+/**
+* Creates a Drupal Ajax 'add_css' command.
+*
+* This method will add css via ajax in a cross-browser compatible way.
+*
+* This command is implemented by Drupal.ajax.prototype.commands.add_css()
+* defined in misc/ajax.js.
+*
+* @param $styles
+*   A string that contains the styles to be added.
+*
+* @return
+*   An array suitable for use with the ajax_render() function.
+*
+* @see misc/ajax.js
+*/

Mmm, it looks to me like the indentation is off here. There should be a space before the stars. Did I just not notice it before? Sorry. :(

Also, did you open that followup by any chance with your other fixes? You can link it here for reference.

27 days to next Drupal core point release.

xjm’s picture

Assigned: xjm » Unassigned

Not quite sure how or why I assigned this to myself.

JeremyFrench’s picture

Status: Needs work » Needs review
StatusFileSize
new2.05 KB

Fixed formatting as mentioned in #20.

JeremyFrench’s picture

StatusFileSize
new2.05 KB

Adding correctly named file.

mradcliffe’s picture

I tested a workaround for Drupal 7 while I was working with CTools and vertical tabs that relied on the same conditional code (see hack below).

I am slightly concerned about the use of regex, but I don't think there is a better alternative since the input is being fed by drupal_get_css(). Is it possible to overload addImport() with bogus data? Otherwise this looks good to me.

  drupal_add_library('system', 'drupal.vertical-tabs');
  drupal_add_js('
    if (document.styleSheets[0].addImport) {
      document.styleSheets[0].addImport(' . DRUPAL_ROOT . '/misc/vertical_tabs.css);
    }  
  ', 'inline');
nod_’s picture

Issue tags: +JavaScript

Tagging,

#23 looks pretty good, don't have IE to test though. Maybe sepgil can confirm ?

xjm’s picture

Tagging for manual testing.

xjm’s picture

Issue tags: +Needs manual testing

Ahem.

anthbel’s picture

Status: Needs review » Needs work
Issue tags: +JavaScript, +Novice, +Needs manual testing, +Needs backport to D7

The last submitted patch, lazy-loading-css-ie-1071818-22.patch, failed testing.

anthbel’s picture

Status: Needs work » Needs review
StatusFileSize
new2.08 KB

Rerolled for Drupal 8.x.

xjm’s picture

Status: Needs review » Needs work

Thanks anthbel!

+++ b/core/misc/ajax.jsundefined
@@ -616,6 +616,22 @@ Drupal.ajax.prototype.commands = {
       .removeClass('odd even')
       .filter(':even').addClass('odd').end()
       .filter(':odd').addClass('even');
+	 },

Looks like there's a small indentation issue here. We'll want to fix that, then assuming the patch passes testbot, we can try to test it manually again.

anthbel’s picture

Status: Needs work » Needs review
StatusFileSize
new2.08 KB

Corrected the indentation.

xjm’s picture

StatusFileSize
new654 bytes
new2.09 KB

Fixing the whitespace in a docblock. (Not changing the wording on account of #1337022: [policy, no patch] Create/adopt JavaScript docs standards compatible with a JS documentation parser.)

Now let's get some manual testing in all versions of IE, and also confirm that there are no regressions in other browsers. If someone could post explicit steps to reproduce the bug, that would help. Thanks!

JeremyFrench’s picture

Thanks for the re roll.

XJM there is a minimal module in #11 which demonstrates the bug. It should be self explanatory.

Niklas Fiekas’s picture

Status: Needs review » Needs work
+++ b/core/misc/ajax.jsundefined
@@ -616,6 +616,24 @@ Drupal.ajax.prototype.commands = {
       .filter(':even').addClass('odd').end()
       .filter(':odd').addClass('even');
+  },
+  /**
+   * Command to add css.

Looks like an empty line is missing there.

xjm’s picture

Status: Needs work » Needs review
StatusFileSize
new318 bytes
new2.1 KB

Silly JavaScript.

star-szr’s picture

I attempted a manual test using the module in #11.

1. Fresh install of 8.x-dev
2. Install and enable the module in #11
3. Navigate to /test1071818
4. Click "Test Issue" link

I then got sent to a page full of JSON at /test1071818/test:

[{"command":"settings","settings":{"basePath":"\/","pathPrefix":"","ajaxPageState":{"theme":"bartik","theme_token":"hL6gVpPUzHmLE_zf1mCgC6h6RKtu545LqQ-JmW3Refo"},"overlay":{"paths":{"admin":"node\/*\/edit\nnode\/*\/delete\nnode\/*\/revisions\nnode\/*\/revisions\/*\/revert\nnode\/*\/revisions\/*\/delete\nnode\/add\nnode\/add\/*\noverlay\/dismiss-message\nuser\/*\/shortcuts\nadmin\nadmin\/*\nbatch\ntaxonomy\/term\/*\/edit\ntaxonomy\/term\/*\/delete\nuser\/*\/cancel\nuser\/*\/edit\nuser\/*\/edit\/*","non_admin":"admin\/structure\/block\/demo\/*\nadmin\/reports\/status\/php"},"ajaxCallback":"overlay-ajax"}},"merge":true},{"command":"insert","method":"append","selector":".region-content .content","data":"\u003Cdiv class=\u0022issue_pass\u0022\u003E\u003Ch3\u003EPass\u003C\/h3\u003EThis should be shown if the issue is fixed in this setup.\u003C\/div\u003E\n \u003Cdiv class=\u0022issue_fail\u0022\u003E\u003Ch3\u003EFail\u003C\/h3\u003EThis will be shown if the issue is not fixed in this setup.\u003C\/div\u003E","settings":null}]

Testing the module in IE6-8, the browser tried to download the JSON-containing file instead of showing it in the browser. Applying the patch in #36 didn't make a difference in any browser I tested in.

My impression from looking at the test module code is that the pass/fail is supposed to be displayed in-browser. I attempted clearing my cache as well with no change.

Perhaps we can clarify how the test module is supposed to work and any other necessary configuration that may be required.

anthbel’s picture

StatusFileSize
new1.16 KB

Rerolled the module in #11, because of the change in Drupal 8 core directory structure.

anthbel’s picture

StatusFileSize
new23.84 KB
new25.62 KB

Applied #36 and tested with #38 on IE7 and IE8. Results attached.
Have not found an impact on chrome and FF.

Zgear’s picture

Status: Needs review » Reviewed & tested by the community

Tested for in safari and opera, both passed. I daresay RTBC.

catch’s picture

Assigned: Unassigned » nod_

Let's give nod_ a chance to sign off on this before it goes in, assigning to the new JavaScript maintainer!

nod_’s picture

Status: Reviewed & tested by the community » Needs work

Actually I've been stalking this one for a while :D

There is a leaking var in there. Otherwise this looks good, I'm doing a few more tests and I'll send a patch later.

nod_’s picture

Status: Needs work » Needs review
StatusFileSize
new2.78 KB

Ok so there are several issues here.

  • a couple of leaking vars.
  • @import is only used for unaggregated CSS, which is the uncommon use case (production last way longer than development) so it is only useful if response.data has @import somewhere.
  • regex way too complicated. there is no need to check for weird import statement, we generate the markup, if it's somehow overriden, the add_css command will need to be overriden anyway. With a minor addition to the markup (two \n) we can use the multi-line mode of regxp, speeding this thig way up: http://jsperf.com/drupal-import-regxp benchmark needs ie testing but i'm confident it'll be the same.

Here is an updated patch, I don't have IE but that should work fine :)

sun’s picture

Status: Needs review » Needs work
+++ b/core/misc/ajax.js
@@ -616,6 +616,25 @@ Drupal.ajax.prototype.commands = {
+  /**
+   * Command to add css.
+   *
+   * Uses the proprietary addImport method if available as browsers which
+   * support that method ignore @import statements in dynamically added
+   * stylesheets.
+   */
+  add_css: function (ajax, response, status) {
+    // Add the styles in the normal way.
+    $('head').prepend(response.data);
+    // Add imports in the styles using the addImport method if available.

1) Had to read the description twice to parse it, and after parsing, I think (or hope) I get what it tries to tell, but the actual text is not proper English.

2) I do not understand why the styles are added both in the normal way and with the proprietary method. The JSDoc description should also clarify and explain why that is done.

3) The inline comments within the function body could use some better wording, too.

Lastly, "CSS" in comments should always be all-uppercase.

+++ b/core/misc/ajax.js
@@ -616,6 +616,25 @@ Drupal.ajax.prototype.commands = {
+    if (/@import/.test(response.data) && document.styleSheets[0].addImport) {
+      var match, importMatch = /^@import url\("(.*)"\);$/igm;
+      while (match = importMatch.exec(response.data)) {
+        document.styleSheets[0].addImport(match[1]);

1) It looks like the check for document.styleSheets[0].addImport is the primary and much faster condition, so it should come first.

2) It looks like we're performing two different regex matches on the response.data, whereas the initial is less specific, but the actual one is not very complex either, so we should just perform the actual/second one.

3) I'm concerned about any possible false-positives of this manual parsing. Did anyone investigate this? If so, the results of that could deserve an inline comment.

4) Has this been tested with inline CSS returned by the server?

JeremyFrench’s picture

@nod

@import is only used for unaggregated CSS, which is the uncommon use case (production last way longer than development) so it is only useful if response.data has @import somewhere.

Is this the case when drupal_add_css us used in an ajax command?

@sun
does this read better?

This command is used to add css in ajax commands. In most cases this is simply adding the CSS to the head. But some browsers ignore @import statements when this is done. In these cases this function will detect the existence of a proprietary addImport method to add the import style sheets.

nod_’s picture

Status: Needs work » Needs review
StatusFileSize
new2.78 KB

Here is for the code:

  1. that's true, changed
  2. also true, I supposed the multiline wouldn't work but boy I was wrong.
  3. it's unlikely, do you have something in mind? this regex is treating each line as a different string so ^ and $ can be used to check for start and end of pattern.
  4. Inline CSS? like actual rules, not just import statements? it's only @import that IE needs help with he can deal with inline css just fine otherwise.

Haven't touched at comments

JeremyFrench’s picture

Patch looks good to me. Needs more eyes though.

mradcliffe’s picture

I think Firefox 10 may be throwing a JS error on this now where it wasn't before in previous versions (I think, I can't test anymore). Or maybe it's Firebug?

JeremyFrench’s picture

StatusFileSize
new2.81 KB

Couldn't reproduce the firefox10 bug. But doing a quick test in IE showed it was no longer working.

The regex was being used for a test and not being reset for the loop. This should now be fixed in this patch.

JeremyFrench’s picture

StatusFileSize
new2.81 KB

Ooops. Attaching correctly named file.

Status: Needs review » Needs work

The last submitted patch, core-js-IE-addimport-1071818-49.patch, failed testing.

JeremyFrench’s picture

Status: Needs work » Needs review
StatusFileSize
new2.81 KB

Sorry for spam. This should work.

ryan.ryan’s picture

The patch in 52 passed testing in FF and Webkit browsers.

NROTC_Webmaster’s picture

The patch in #52 works for Chrome v19 and IE 8

nod_’s picture

StatusFileSize
new2.79 KB

learing stuff on regxp is always fun :)

so using string.search(regexp) will give the same result as regexp.test(string), but without messing with the search index and it's faster too :) http://jsperf.com/drupal-import-regxp/3

needed a reroll after the doc change too.

sun’s picture

StatusFileSize
new2.72 KB

Sorry, but what I meant was this.

And I don't really care for performance of IE, as long as it requires dirty workarounds like this.

That said, this needs to be tested against IE10, as Microsoft announced that they removed/resolved the stylesheets limitations, so the regular/standard way should work in IE10, too -- however, the addImport method might still exist, as Microsoft tends to keep quirks around, and so in turn, we need to make sure that stylesheets don't get imported twice.

nod_’s picture

You can't use regexp like that in JS. To have access to the substring you have to use .exec(), .match() gives you the whole thing.

Your patch doesn't work for me.

dig1’s picture

Ok here are some testing results for IE9:

First install
1) Downloaded & installed latest D8 --dev
2) Downloaded & installed #38 test-rig
3) Cleared cache on server and browser
4) Loaded /test1071818
5) Clicked on 'Test' and got ' Fail This will be shown if the issue is not fixed in this setup.'
6) Downloaded & patched http://drupal.org/files/core-js-IE-addimport-1071818-55.patch
7) Cleared cache on server and browser
8) Loaded /test1071818
5) Clicked on 'Test' and got 'Pass This should be shown if the issue is fixed in this setup.'

Second install
1) Downloaded & installed latest D8 --dev
2) Downloaded & installed #38 test-rig
3) Cleared cache on server and browser
4) Loaded /test1071818
5) Clicked on 'Test' and got ' Fail This will be shown if the issue is not fixed in this setup.'
6) Downloaded & patched http://drupal.org/files/drupal8.ajax-css-ie.56.patch
7) Cleared cache on server and browser
8) Loaded /test1071818
5) Clicked on 'Test' and got 'Fail This will be shown if the issue is not fixed in this setup.'

So for IE9 at the moment it appears that:
- core-js-IE-addimport-1071818-55.patch works
- drupal8.ajax-css-ie.56.patch does not work

Cheers

NROTC_Webmaster’s picture

The patch in 56 fails in IE8

xjm’s picture

Thanks Dig1 and NROTC_Webmaster!

Can we settle on #55 so we can finish manually testing this on all browsers and versions of IE, and get this bugfix in?

JeremyFrench’s picture

Tested patch in #55 on IE10 and IE10PP4, I get pass in both platforms.

Issue still occurs without patch, so they haven't fixed this particular issue even in IE10.

Personally I think the #55 patch should be RBTC, but I have had to much of a hand it it to change status myself.

kristiaanvandeneynde’s picture

Cross referencing with #1461322: Fix AJAX add_css – insert the needed CSS assets after the already-inserted ones

The patch in #55 still prepends scripts to the head.
If we are replacing ajax_command_prepend with a new command (ajax_command_add_css), we may as well 'get it right' in that new command?

xjm’s picture

Changes like that should probably be done in followup issues, I think, but as it's JS I don't know the full implications. It merits its own, separate discussion (probably in the linked issue). This issue is specifically about resolving the bug, whereas the other issue needs discussion and consensus before we'd go forward with it. Thanks!

kristiaanvandeneynde’s picture

I agree that the discussion about that subject should take place in the ticket for it.

However, the code that is causing that issue in the first place will be completely removed by the patch in #55 and replaced with new code that still implements the weird behaviour.

If we are replacing the code anyway, why not try to squash two issues in one patch?
The only change to the patch in #55 would be appending the lazy loaded styles to the head instead of prepending them.

The alternative would be:

  • Commit this patch
  • Update other issue referring to the new code and that the bug still lives in it
  • Wait for a while until that issue is RTBC
  • Only then fix the other issue (perhaps a few months from now)

May as well benefit from the current momentum?

xjm’s picture

Issue tags: -Needs manual testing

Thanks @kristiaanvandeneynde. My perspective is that this is a major bug that has a complete, existing solution. The other is not. In general, I don't think it's wise to postpone major bugs on non-major tasks.

If the JavaScript needs to be changed, I don't know enough to evaluate the proposed changes, but much of the "current momentum" as you call it is from people working on this issue during core office hours, which I facilitate. However, I am not going to keep spending people's time re-testing it over cleanups that don't change the functionality.

Untagging. Retag when this patch is ready for testing that needs to precede an RTBC.

JeremyFrench’s picture

Issue tags: +Needs manual testing

@kristiaanvandeneynde
Unfortunately this patch is very near consensus and being RBTC, compounding two issues will potentially take much longer to work on and decide if it is even needed. Trying to include it in here is more likely to kill the momentum rather than getting two issues resolved.

I can understand that it looks strange but it means that both issues get proper discussion in isolation.

Just out of interest have you tried patch #55 you may find that it resolves the issue you have. Prepending or Appending in IE will still fail without this patch.

effulgentsia’s picture

I think append vs. prepend warrants a separate discussion, and therefore, issue, and not be combined here. One problem with append is that it would mean module CSS potentially overriding theme CSS. Maybe it's better than the current prepend, but to me, it's not yet obvious that it is, and if it is, that it can be backported to D7, so let's hash that out there without derailing this bugfix.

JeremyFrench’s picture

Issue tags: -Needs manual testing

Remove tag that was added in error.

(is this a novice issue?)

xjm’s picture

Fixing crosspost. @nod_, please let me know when this issue is ready for testing again! Thanks.

xjm’s picture

Issue tags: -Novice

Novice was also for the manual testing. :)

nod_’s picture

#55 is good for review and «works for me»™ on IE7–9, unless sun has something to say about it.

effulgentsia’s picture

Status: Needs review » Needs work
+++ b/core/includes/common.inc
@@ -3347,7 +3347,7 @@ function drupal_pre_render_styles($elements) {
-            $element['#value'] = implode("\n", $import_batch);
+            $element['#value'] = "\n" . implode("\n", $import_batch) . "\n";

If this is necessary for the JavaScript to work, then we need to add a test to ensure someone doesn't come along and try to remove those seemingly unnecessary newlines. A code comment also wouldn't hurt.

Otherwise, I'm +1 for this, but am not qualified to RTBC it.

xjm’s picture

Issue tags: +Needs tests

Tagging per #72.

nod_’s picture

Issue tags: +Novice

The point of line breaks are to make the javascript regex very simple. I'm not particularly good at writing doc and comments, i'll let that to someone else :)

before the code returned by the add_css command was like that:

<style>@import url("url/file1.css");
@import url("url/file2.css");
@import url("url/file3.css");
@import url("url/file4.css");</style>

To dramatically simplify the regex the string returned needs to be like that:

<style>
@import url("url/file1.css");
@import url("url/file2.css");
@import url("url/file3.css");
@import url("url/file4.css");
</style>

now we can use the multi-line flag of javascript regex, treating each line (separated by \n) as a completely different string. That means we can use ^ and $ on one line at a time. We don't have to worry about style tags since they'll never match the regex.

NROTC_Webmaster’s picture

Status: Needs work » Needs review
StatusFileSize
new1.8 KB
new3.1 KB

Updated #55 with comments based on #74.

xjm’s picture

That comment looks good. Thanks @NROTC_Webmaster.

So now we just need an automated test that confirms that the $element['#value'] begins and ends with a linebreak.

nod_’s picture

StatusFileSize
new5.26 KB

Let's see what bot says

Status: Needs review » Needs work

The last submitted patch, core-js-IE-addimport-1071818-77.patch, failed testing.

nod_’s picture

Cool, CSS newline test passes. The new ajax_command_add_css fails though.

maxtorete’s picture

Is this bug present on Drupal 7? I'm having the same troubles with css injection on IE 7-9. If so, will the patch backported to D7 core?

Thanks!

nod_’s picture

You should really turn css aggregation on Maxtorete, it's good for your site and should get rid of this issue.

JeremyFrench’s picture

@nod_ I don't think aggregation will always get rid of this issue.

@maxtorete yes this is an issue in D7. And the patch should be backported.

nod_’s picture

it will unless you're adding @import in some custom inline CSS. and even then it might be picked up anyway.

help on the test is welcome btw :)

lliss’s picture

StatusFileSize
new5.52 KB

Since there were so many changes surrounding psr-0 this had to be rerolled. Doesn't fix the problem yet but at least the patch can be applied cleanly again.

lliss’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Issue tags: -JavaScript, -Needs tests, -Novice, -Needs backport to D7

The last submitted patch, core-js-IE-addimport-1071818-84.patch, failed testing.

yashadev’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Issue tags: +JavaScript, +Needs tests, +Novice, +Needs backport to D7

The last submitted patch, core-js-IE-addimport-1071818-84.patch, failed testing.

nod_’s picture

Assigned: nod_ » Unassigned

Don't have time to deal with it.

Bug is fixed by the patch, the new tests needs some fixing.

star-szr’s picture

Assigned: Unassigned » star-szr

I'm going to take a look at the tests.

star-szr’s picture

StatusFileSize
new3.73 KB
new6.83 KB
new2.27 KB

I did some manual testing using the test module in #38 . The JavaScript change introduced back in #55 breaks the test module (failure message is displayed) in IE 6-8, IE 9 still tests fine. The patch I'm attaching here is still broken in IE 6-8.

I tested with these steps:

  1. Did a checkout of 8.x at commit 3c78ca4.
  2. Installed and enabled the module from #38 .
  3. Applied the patch in #52 .
  4. Cleared cache.
  5. Ran through tests (click "Test Issue" link on /test1071818) in IE 6-9, all passed.
  6. Removed the changes from #52 .
  7. Applied the patch in #55 .
  8. Cleared cache.
  9. Ran through tests (click "Test Issue" link on /test1071818) in IE 6-9, only IE 9 passed.

The patch here adds to ajax_forms_test.module to allow the new add_css command to be tested, and corrects the expected return in the add_css test.

Also removed an extra newline introduced in #84 .

Edit: linkified comment numbers.

Assigned: star-szr » Unassigned
Issue tags: -JavaScript, -Needs tests, -Novice, -Needs backport to D7

The last submitted patch, 1071818-91-tests.patch, failed testing.

star-szr’s picture

Status: Needs work » Needs review
Issue tags: +JavaScript, +Needs tests, +Needs backport to D7

#91: 1071818-91.patch queued for re-testing.

Just searched and found #1655422: Random test failures in SearchCommentTest, so I'm thinking the failure was unrelated.

star-szr’s picture

Status: Needs review » Needs work

Much better. Now we need to fix this in IE 6-8.

yashadev’s picture

I thought Drupal 8 is dropping support for IE 6?

effulgentsia’s picture

Yes, for D8, we only need this to work on IE8. For a D7 backport though, it needs to work on IE6 and 7.

star-szr’s picture

Right, thanks for clarifying that @effulgentsia!

nod_’s picture

Status: Needs work » Needs review
StatusFileSize
new6.85 KB

Took the JS code from #52, please retest. If it works rtbc it please :)

star-szr’s picture

Issue tags: -Needs tests

Thanks @nod_! I just did manual testing in IE 6-9, they all passed now. I think I'm a bit too close to the issue to RTBC though.

Removing the "Needs tests" tag.

nod_’s picture

Status: Needs review » Reviewed & tested by the community

nah it's fine, it's an edge case anyway. Thanks for giving this the last push it needed :)

RTBC since #99 successfully tested the patch and it's green.

webchick’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

I confess I don't know fully what's happening here, but it seems like a decent bug fix and comes with tests and has buy-in from the right people.

Committed and pushed to 8.x.

This will need a backport to D7.

star-szr’s picture

Assigned: Unassigned » star-szr
star-szr’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new6.38 KB
new3.32 KB

Backported to D7. I had to change the test assertion for the newlines within <style> tags in CascadingStylesheetsTestCase::testRenderFile() (see #74). This assertion needed to be revised because in D7 <style> tags have a type="text/css" attribute added by default.

Re-tested in IE 6-9 with the test module in #11, all passed.

beeradb’s picture

#103: 1071818-103-tests.patch queued for re-testing.

beeradb’s picture

Status: Needs review » Needs work

I just tested this in IE9. I tried it both via adding commands directly to the ajax commands array, and calling drupal_add_css and letting ajax_render() add the command. In both cases the add_css ajax method was called, and even passed through to the line document.styleSheets[0].addImport(match[1]); with the correct CSS file, but the file was either never actually loaded, or did not properly apply.

nod_’s picture

Assigned: star-szr » Unassigned
Priority: Major » Normal
star-szr’s picture

Issue tags: +Needs manual testing

Can we get another confirmation for the result in #105? I used the test module in #38, and the patch in #103 passed in IE 6-9.

Patch still applies cleanly to 7.x.

star-szr’s picture

I meant the test module from #11 (before the /core change).

jantimon’s picture

#103 works for me (IE 8)

Snipon’s picture

It works fine in IE8 until you turn CSS aggregation on.

micbar’s picture

works for me on IE 7 and 8

micbar’s picture

Status: Needs work » Needs review

#103: 1071818-103.patch queued for re-testing.

gielfeldt’s picture

StatusFileSize
new6.38 KB

Rebased (and updated) for 7.x-dev.

star-szr’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Thanks @gielfeldt. This needs another reroll.

I am uploading the test module from #38 as a patch for easier testing (it can also be tested via simplytest.me).

star-szr’s picture

StatusFileSize
new3.22 KB

Ahem, here is the actual patch for the test module :)

kristofferwiklund’s picture

Assigned: Unassigned » kristofferwiklund

I will look at that.

kristofferwiklund’s picture

Issue tags: -Needs reroll

Patch in #113 is fine. Does not need rerolling.

kristofferwiklund’s picture

StatusFileSize
new3.15 KB

Uppdated test code in #114 for 7.x.

The test fails for current 7.x for IE 8. The test pass for IE10.

After applying patch in #113 the code works also for IE8.

gielfeldt’s picture

Issue summary: View changes
StatusFileSize
new6.37 KB

New patch for latest dev

miroslavbanov’s picture

The patch in #119 applies successfully and completely breaks ajax.js :

  add_css: function (ajax, response, status) {
    // ...
  }

  /**
   * Command to update a form's build ID.
   */
  updateBuildId: function(ajax, response, status) {

At the end of the add_css function, there should be a "," or the JS object is broken and can't be parsed. I wish there was a test that can catch this problem.

gielfeldt’s picture

StatusFileSize
new6.37 KB

The patch in #119 applies successfully and completely breaks ajax.js

I've attached a patch addressing this for now. But we should add some tests.

At the end of the add_css function, there should be a "," or the JS object is broken and can't be parsed. I wish there was a test that can catch this problem.

I agree. However, I had problems with jslint and gave up ...

gielfeldt’s picture

Status: Needs work » Needs review
miroslavbanov’s picture

I can say that the patch #121 works for me, for some pretty complex Drupal installations, but I don't know how the patch works, and I haven't actually reviewed it, so I won't mark it RTBC.

mgifford’s picture

#121 is a good port from D8 from my review of it.

@MiroslavBanov can testify that it is working for his Drupal installations.

I'm not certain what is the best way to test this though. We don't do a lot of work with Windows & haven't experienced this Lazy Loading issue that I'm aware of.

This was committed to D8 2 years ago. This should be easy to mark RTBC. I'd just like to have a clear sense of what I'm testing.

miroslavbanov’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new12.27 KB

Its easy enough to reproduce:

  1. Install:
    • link 1.2
    • linkit 3.1
  2. Create a linkit profile with settings:
    • Profile type: Fields
    • Search plugins: Node
    • Insert plugin: Raw URL
    • Insert paths as: Raw paths
  3. Create a Link field, with this linkit profile enabled for it.
  4. Generate some content.
  5. Use the linkit autocomplete in IE8 and despair.

See linkit profile autocomplete with and withot patch #121:
[Broken without patch]

I'm going ahead and marking this RTBC, before the reason for this patch is completely dead.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 121: 1071818-121.patch, failed testing.

mgifford queued 121: 1071818-121.patch for re-testing.

dcam’s picture

Status: Needs work » Reviewed & tested by the community

Re-setting RTBC status.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 121: 1071818-121.patch, failed testing.

dcam queued 121: 1071818-121.patch for re-testing.

dcam’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 121: 1071818-121.patch, failed testing.

mgifford queued 121: 1071818-121.patch for re-testing.

kristofferwiklund’s picture

Assigned: kristofferwiklund » Unassigned
dcam’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 121: 1071818-121.patch, failed testing.

Cottser queued 121: 1071818-121.patch for re-testing.

dcam’s picture

Status: Needs work » Reviewed & tested by the community
miroslavbanov’s picture

What is the deal with all this status change? The patch is green, but the there are messages that it "fails testing". Is this because of some problem with the testbot?

micbar’s picture

like #125 I hope that this patch gets committed before it becomes obsolete.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 121: 1071818-121.patch, failed testing.

mgifford queued 121: 1071818-121.patch for re-testing.

dcam’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 121: 1071818-121.patch, failed testing.

mgifford queued 121: 1071818-121.patch for re-testing.

dcam’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 121: 1071818-121.patch, failed testing.

mgifford queued 121: 1071818-121.patch for re-testing.

oriol_e9g’s picture

Status: Needs work » Reviewed & tested by the community

#121 green

micbar’s picture

please commit soon, the testbot is constantly reverting this to "needs work". See #140.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks!

Fixed the following on commit:

--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -664,7 +664,7 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase {
     // Verify that newlines are properly added inside style tags.
     $query_string = variable_get('css_js_query_string', '0');
     $css_processed = "<style type=\"text/css\" media=\"all\">\n@import url(\"" . check_plain(file_create_url($css)) . "?" . $query_string ."\");\n</style>";
-    $this->assertEqual(trim($styles), $css_processed, t('Rendered CSS includes newlines inside style tags for JavaScript use.'));
+    $this->assertEqual(trim($styles), $css_processed, 'Rendered CSS includes newlines inside style tags for JavaScript use.');
   }

  • David_Rothstein committed 62e874b on 7.x
    Issue #1071818 by JeremyFrench, nod_, Cottser, gielfeldt, xjm, anthbel,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.