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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 1059100.patch | 438 bytes | cyberwolf |
| #2 | issue1059100.tgz | 1.03 KB | cyberwolf |
Comments
Comment #1
rfayHi - 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
Comment #2
cyberwolf commentedOk, here's a small module which shows the erroneous behavior.
Comment #3
cyberwolf commented... and a patch
Comment #4
rfayWell now, demonstration + patch! That's pretty cool. Thanks!
Comment #5
cyberwolf commentedThe patch seems to trigger a PHP notice a bit further in the file:
Comment #6
inolen commentedI 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.
Comment #7
rfayThis will have to go into D8 first; Sorry for the delay. Also sorry I haven't reviewed it yet.
Comment #8
cyberwolf commentedNo 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.
Comment #9
cyberwolf commentedAny news on this one?
Comment #10
rfayI still have it starred :-) You should look for other reviewers. sun would be a good (great) one.
Comment #11
cyberwolf commentedLooks 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.