This issue has been kicking around for ages, but I don't think there's an overall issue for it yet.
In Drupal 7 we introduced #attached for CSS, JS and some other things so that assets which are needed by a specific element can be properly cached along with its parent element. If you use drupal_add_*() and your code doesn't run (because it's cached), then your CSS won't be added to the page.
The WSCCI initiative is try to allow for blocks to be rendered at their own URI, to allow for parallel rendering of page requests via mechanisms such as CSI/SSI/ESI, this runs into exactly the same problem (and some extra ones like the parent page not necessarily being served by PHP at all) as the render cache does.
So for either independently rendered blocks, or our render caching to work reliably, we need to finish the job and use this stuff consistently.
There's really two parts to this:
- supporting #title, #breadcrumbs and similar with #attached - extending the existing support for library/js/css/link, then ensuring core is consistent in using them and deprecating or removing wholesale the old functions.
- separately, figuring out how #attached will work with the response object - assuming most callbacks will be returning those rather than render arrays (although we'll likely need support for both while both co-exist anyway). I think there's already an issue for this bit but I can't find it at the moment.
Related issues:
#1811828: Use #attached to find the css/js of a view
#1830588: [META] remove drupal_set_title() and drupal_get_title()
#1029460: Find a better hook than hook_init() for drupal_add_js() and drupal_add_css()
#1839348: Make CSS/JS aggregation work for parallel rendering
#1762204: Introduce Assetic compatibility layer for core's internal handling of assets
#1947536: Convert drupal_get_breadcrumb() and drupal_set_breadcrumb() to a service
#1981644: Figure out how to deal with 'title/title callback'
#2032535: Resolve 'title' using the route and render array
#2073817: [META] Remove drupal_set_message()
#2061913: Remove drupal_set_breadcrumb and LegacyBreadcrumbBuilder in Views module
#2073819: [META] Remove direct calls to drupal_add_css()
#2073823: [META] Remove drupal_add_js() calls
Comments
Comment #1
sunI followed up on #1830588-3: [META] remove drupal_set_title() and drupal_get_title() — it seems the same pattern is being proposed for some other things that share some aspects with the page title (e.g., breadcrumbs), and I don't think the proposed pattern will work out, so it might make sense to hash it out for the page title first.
Comment #2
nod_A DX detail for getting rid of drupal_add_js is how we handle JS settings, using #attached is a pretty sucky DX compared to drupal_add_js().
First step of this was to change all
drupal_add_js
todrupal_add_library
. The only part I couldn't change was a piece of code line 247 of thecolor.module
.And I guess I can close #1762204: Introduce Assetic compatibility layer for core's internal handling of assets and say it's B&L that'll fix it, right?
Comment #2.0
nod_Updated issue summary.
Comment #3
catchI couldn't find #1762204: Introduce Assetic compatibility layer for core's internal handling of assets when typing up the issue summary, added it. Not sure why we'd close that or what B&L means?
#attached may be sucky DX, we can obviously look at making it easier, or the response object extension will have to tackle that too.
Comment #4
nod_Blocks and Layout.
Closing since both functions will (hopefully) go away with the new way of processing the #attach suff?
Comment #5
moshe weitzman CreditAttribution: moshe weitzman commentedBlocks and Layouts ... Perhaps this is a slight DX regression but it is in the interest of caching that actually works. This isn't really optional.
Comment #6
catch@nod_ I wouldn't close it yet, the new way of processing the #attach stuff doesn't exist yet, i know sdboyer is thinking about it but not sure where the issue is.
Comment #7
sdboyer CreditAttribution: sdboyer commentedwhat, this can't be the issue? :)
unless someone recommends that i split it out, i plan to roll them in with the controller patch (#1812720: Implement the new panels-ish controller [it's a good purple]). that's code i'm literally writing that code right now, since we're down to ONE failure on blocks-as-plugins :)
Comment #8
David_Rothstein CreditAttribution: David_Rothstein commentedThis is an important issue, but I don't believe it's a critical task (see http://drupal.org/node/45111 and http://drupal.org/node/1181250). Specifically, although we should fix this throughout core, if contrib modules are failing to use #attached it's already a bug against that module, not really core's fault directly. Also, none of the issues that this is a blocker for are marked critical - at least not as of a few minutes ago, anyway :)
If you disagree and feel this must still be marked critical, please provide a very specific justification and keep in mind that every critical issue significantly prevents other features that people are working hard on from getting into Drupal core, due to the issue queue threshold policy (until/unless #1810428: [Policy, no patch] Adjust major and critical task thresholds during code thaw is addressed, at any rate). Note that I am not singling out this issue for particular attention but rather (slowly) trying to go through the issue queue and do this in many places so that other features still have a chance to get into Drupal core soon without the thresholds getting in the way. I am trying my best to be impartial, and of course, just because an issue isn't marked "critical" certainly doesn't mean it's unimportant to work on. You can follow my progress via the tag I've just added to this issue :)
Comment #9
sdboyer CreditAttribution: sdboyer commentedfinally got my giant honking followup posted: #1871596: Create a PartialResponse class to encapsulate html-level data [Moving to sandbox]
Comment #10
David_Rothstein CreditAttribution: David_Rothstein commentedSorry for the noise; I'm told that slashes in tags can break the autocomplete on drupal.org.
Comment #11
effulgentsia CreditAttribution: effulgentsia commentedI added a comment in #1762204-40: Introduce Assetic compatibility layer for core's internal handling of assets for why I think this issue is separate from that one, needs to happen regardless, and can be worked on in parallel. Adding the caching tag to try to keep everything that's needed for ESI discoverable.
Comment #12
xjmComment #12.0
xjmUpdated issue summary.
Comment #13
Crell CreditAttribution: Crell commentedTagging.
Comment #14
tim.plunkettOpened #1998102: Remove the global JS futzing in ViewsFormBase::getForm() for that tricky bit.
Comment #15
manarth CreditAttribution: manarth commentedSo I picked off some of the low-hanging fruit in #2003524: Remove drupal_add_css from() help.module — use #attached, #2003564: Remove drupal_add_css() from block.module — use #attached, and #2003574: Remove drupal_add_css() from openid.module — use #attached.
The remaining
drupal_add_css
/drupal_add_js
issues are split between:drupal_add_css()
to get a list of the current css files, then doing some processing on that listIn other words, things that don't necessarily lend themselves to easily swapping to an
#attached
property on a render array.Comment #15.0
manarth CreditAttribution: manarth commentedAdding breadcrumbs issue
Comment #16
Wim Leers#15: Thanks, reviewed & RTBC'd all three of them.
Comment #17
mcjim CreditAttribution: mcjim commentedFour calls to drupal_add_css in theme.maintenance.inc: issue and patch here: #2008270: Remove drupal_add_css() from template_preprocess_maintenance_page() — use #attached
Comment #17.0
mcjim CreditAttribution: mcjim commentedUpdated issue summary.
Comment #17.1
mcjim CreditAttribution: mcjim commentedAdded list of issues to remove drupal_add_css and drupal_add_js.
Comment #18
mcjim CreditAttribution: mcjim commentedUpdated summary and added patch for colour module: #2010636: Remove drupal_add_css() and drupal_add_js() from color.module — use #attached
Comment #18.0
mcjim CreditAttribution: mcjim commentedAdded #2010636: Remove drupal_add_css() and drupal_add_js() from color.module — use #attached
Comment #19
mcjim CreditAttribution: mcjim commentedUpdated summary and added patch for book module: #2012526: Remove drupal_add_css() from book.module — use #attached
Comment #19.0
mcjim CreditAttribution: mcjim commentedAdded #2012526: Remove drupal_add_css() from book.module — use #attached
Comment #20
catchWe don't have an issue for drupal_set_message() yet.
Comment #21
Crell CreditAttribution: Crell commentedThe right way to do drupal_set_message() is to use flash messages on the Symfony session, on the request object. Which of course is still blocked by Simpletest: #1858196: [meta] Leverage Symfony Session components
Comment #22
catchThat's not related to this issue at all.
Currently we put stuff in session, then at the end of the full page request, print the messages and empty the messages from session.
If something gets added to session after that happens, or the page doesn't print (i.e. a form redirect), then the messages will be in session for the next request and get printed.
Whether the messages are in the current session.inc session system of Symfony's has not bearing on this as far as I can tell - drupal_set_message() is more or less just a wrapper around $_SESSION, so the implementation is very similar, just with a sillier name.
Where it breaks down in *SI is that if you have a separate PHP request, the main one cannot know that something was added to $_SESSION in that request, so the messages will now get shown on the next full page.
At least in the Symfony code shipped with core, there's nothing at all which deals with this or any indication it's been dealt with. So there needs to be some layer which collects the messages at the end of the real requests, formats them, and makes them available to the overall page.
It's not as bad as assets/titles/breadcrumbs etc. because the messages would still get shown eventually, but it'd mean a lot more dpm()/error messages etc. being shown a request behind - as sometimes happens now if you try to use dpm() in the theme layer or similar.
Comment #23
effulgentsia CreditAttribution: effulgentsia commentedI've discussed this with several people, including Crell, sdboyer, and Dries, and all agree on this being a critical issue, because of the huge performance impact that enabling block and other partial page element caches in core by default would have.
Right. This issue is primarily about fixing the usages in core. Though once we do that, removing the functions themselves, to force contrib to also do things correctly, is pretty easy.
Comment #24
catchI opened #2028415: Mark drupal_add_*() deprecated.
Comment #25
Wim LeersRerolled
However, there are still many other remaining calls to
drupal_add_(css|js)()
. We need issues/patches for those as well.Comment #25.0
Wim LeersRemoving OpenID issue.
Comment #25.1
adammaloneAdded related issue
Comment #26
mcjim CreditAttribution: mcjim commentedI had a list, somewhere. I'll update it and add the issues.
(Most are in tests, iirc.)
Comment #27
Wim Leers#26: yep, typhonius is working on those already! :) I expect he'll file a new issue along with a patch.
Comment #28
dlu CreditAttribution: dlu commentedMoved to cache system per #2050763-16: Refine "base system" component (notes on refactoring of "base system" category here: https://docs.google.com/a/acquia.com/spreadsheet/ccc?key=0AusehVccVSq2dF...).
Comment #29
webchickThis will be an API change, but my understanding is this is implicitly approved because it makes render caching work.
Comment #30
xjmRe-adding tags for #29. Tag Monster!
Comment #30.0
xjmAdded in related issue for bartik.theme
Comment #31
xjmhttps://docs.google.com/a/acquia.com/document/d/1sgxD0l2OM91EqTekXryhdaX... has notes from Portland; looks like it somehow never got linked here.
We still need issues for
drupal_set_breadcrumb()
anddrupal_set_message()
. Adding the latter to the summary.Comment #31.0
xjmUpdated issue summary.
Comment #32
catchdrupal_set_breadcrumb() has an issue open at #2061913: Remove drupal_set_breadcrumb and LegacyBreadcrumbBuilder in Views module.
drupal_set_messsage() is a funny one. Since that adds messages to $_SESSION it's not actually that bad if everything happens in a single request, messages aren't page assets like most other drupal_set_*() stuff.
However in a real *SI situation the message collection via checking $_SESSION isn't guaranteed to run. So that one doesn't feel like a release blocker but could use some discussion.
Comment #33
xjmFiled #2073817: [META] Remove drupal_set_message() for that discussion.
Comment #33.0
xjmUpdated issue summary.
Comment #33.1
xjmUpdated issue summary.
Comment #34
xjmSplit off #2073819: [META] Remove direct calls to drupal_add_css() and #2073823: [META] Remove drupal_add_js() calls to make it easier to get novice contributors working on those tasks.
Comment #35
catchI think all the sub-issues are critical now, so we should close this one.
Comment #35.0
catchUpdated issue summary.
Comment #36
YesCT CreditAttribution: YesCT commented#1743590: Isolated Block Rendering was postponed on this. since this is done, opening that one.