I am working on an application heavily relying on the new Ajax framework in D7, and I am encountering an issue on subsequent ajax calls.

When there is no new CSS to be loaded in a Drupal ajax request, the returned settings.css in the response is an empty array. When this is merged with the current Drupal.settings.css - which is an object - in Drupal.ajax.prototype.commands.settings(), Drupal.settings.css becomes empty as well.

A small test I did with jQuery.extend():

      a = {
        css: { test: 1 }
      }
      
      b = {
        css: []
      }
      
      alert(JSON.stringify(a, null, 4));
      $.extend(true, a, b);
      alert(JSON.stringify(a, null, 4));

a before:

{
  "css": {
    "test": 1
  }
}

and a after:

{
  "css": []
}

Not good...

On any further ajax calls, no additional css will be loaded, because there is a check on $_POST['ajax_page_state']['css'], in ajax_render() in ajax.inc.

Not sure how to solve this best... Any ideas are welcome.

CommentFileSizeAuthor
#3 1059100.patch438 bytescyberwolf
#2 issue1059100.tgz1.03 KBcyberwolf

Comments

rfay’s picture

Hi - Thanks for your report.

Could you please post a complete example (a tiny example module) that demonstrates this behavior? And please provide step-by-step instructions on how to recreate the problem.

Thanks,
-Randy

cyberwolf’s picture

StatusFileSize
new1.03 KB

Ok, here's a small module which shows the erroneous behavior.

cyberwolf’s picture

Status: Active » Needs review
StatusFileSize
new438 bytes

... and a patch

rfay’s picture

Well now, demonstration + patch! That's pretty cool. Thanks!

cyberwolf’s picture

The patch seems to trigger a PHP notice a bit further in the file:

Notice: Undefined index: css in ajax_render() (line 267 of includes/ajax.inc).
inolen’s picture

I was just affected by this same problem, I ended up throwing in a major hack in ajax.js that copied off the Drupal.settings.ajaxPageState.css before the call to $.extend, and then manually extending it with response.settings.ajaxPageState right after the call to $.extend.

rfay’s picture

Version: 7.0 » 8.x-dev
Issue tags: +Needs backport to D7

This will have to go into D8 first; Sorry for the delay. Also sorry I haven't reviewed it yet.

cyberwolf’s picture

No problem.

What's the preferred way of fixing this? Removing the entry at the backend like my patch does, or rather on the JavaScript side as inolen suggests? I can prepare a new patch for D8 then, which also fixes the notice my previous patch causes.

cyberwolf’s picture

Any news on this one?

rfay’s picture

I still have it starred :-) You should look for other reviewers. sun would be a good (great) one.

cyberwolf’s picture

Status: Needs review » Closed (duplicate)

Looks like this was duplicated at #1287368: Drupal.settings.ajaxPageState.css gets overwritten in September 2011 and in the meantime fixed. Marking this one as a duplicate then.