Hm. Is it just me or does the admin_toolbar_tools module cause all pages to become uncacheable for Drupal's dynamic page cache? According to Chromes web inspector they all get the header "X-Drupal-Dynamic-Cache:UNCACHEABLE" when I'm logged in. If I disable that module everything becomes cacheable again (HIT). As far as I could figure out (might be wrong) the reason seem to be the links/routes that have a CSRF token (like "Run cron" etc). The other links seem to be OK (I've commented them out one by one to find out). What I don't understand: Shouldnt this be solved by the placeholdering algorithm? The session cache context shouldnt bubble up to the top...
I installed a minimal Drupal 8.3.5 and enabled only admin_toolbar (and dependencies) and admin_toolbar_tools via Drush.
Is there anybody out there using the admin_toolbar_tools module successfully in conjunction with Drupal's dynamic_page_cache module?
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | interdiff-admin_toolbar_tools-2897309-24-28.txt | 4.53 KB | finne |
| #28 | admin_toolbar-pages_uncacheable-2897309-28-D8.patch | 8.96 KB | adriancid |
| #28 | interdiff.txt | 4.53 KB | adriancid |
Comments
Comment #2
eme commentedHum, strange indeed. Seems major to me.
Comment #3
eme commentedJust tested on a fresh new install 8.3.5 and admin toolbar 1.19. Seems that the core toolbar make it uncachable, not admin toolbar.
You confirm that it was cachable with toolbar enabled ?
Comment #4
rgpublicAh yes, sorry, eme, you are absolutely right, of course. Don't know how I got to this. Weird. When I tried to follow my steps today, I came to the same conclusion as you. It's not the admin_toolbar that is to blame, but the normal toolbar. I filed a follow up, because I still think it's a bit disappointing that all Drupal content editors never see any advantage of the otherwise pretty cool dynamic cache:
https://www.drupal.org/node/2899392
Comment #5
eme commentedIndeed ! I close this issue then.
Comment #6
finneNB: the core issue can be solved by a patch in https://www.drupal.org/node/2899392.
When I apply that patch the page becomes cacheable.
But when I then enable admin_toolbar_tools the page becomes uncacheable again :-(
Comment #7
eme commentedWell, then it is certainly the CSRF token for the cache flush. Hard to see how to solve the issue.
Comment #8
finneCSRF tokens should be placeholderable, but this is not yet fixed in core. However most 'unsafe' links can be turned off with permissions. A content editor role does not need to flush the cache.
Ah I found a token is also set for links to drupal.org. In admin_toolbar_tools.services.yml:
- admin_toolbar_tools.drupalorg
- admin_toolbar_tools.listchanges
- admin_toolbar_tools.doc
Are those necessary?
In fact why are these routed through a controller instead of direct links?
Comment #9
rgpublic"... but this is not yet fixed in core" => Is there a corresponding bug tracker issue? Couldnt find any...
And, yes, editors obviously dont need to clear the cache. Nevertheless it would of course be nice if really everyone could one day take advantage from the cache - also developers. For the time being, I'd have a problem with discoverability: It's totally unexpected behavior for a developer that the cache is never working no matter what you do or which cache tags etc you set. There should at least be some warning or anything on this. For example, now that I know about this, I'd much rather disable that menu of course than having a broken cache as it slows down the whole Drupal experience significantly and the general Drupal 8 claim has always been - as far as I'm aware - "Cache always on by default due to the cool new dynamic cache".
Comment #10
finneHere is a patch that removes _csrf_token: 'TRUE' for links in the admin toolbar, created by admin_toolbar_tools, that are safe without a token.
Admin toolbars will be cacheable by Dynamic Page Cache if these links are present. For the remaining links (cache flushing and cron) that require tokens a separate patch is needed that provides a lazybuilder for these menu items.
Comment #11
adriancid@finne thaks for the patch I think that we can create another issue the handle your patch (#2915778: Remove the _csrf_token from routes that don't need it), as the other can take more time.
Comment #12
finne@adriancid thanks. I'm working on a lazybuilder for the cache and cron items, so the whole toolbar tools is cacheable again :-)
Comment #13
adriancid@finne thanks, reviewing your patch I see the route:
That is only a redirect to:
Do you have idea why we need this? Maybe @eme can help us?
Comment #14
finneRe: #13
I have no idea, same goes for the controller calls that redirect to drupal.org. I think these links could be normal admin_toolbar_tools.links.menu.yml, and it would clean out the controller quite a bit.
Comment #15
adriancid@finne let see if @eme can say something about this and I can change the behavior if needed.
Comment #16
eme commentedI do agree for the admin/development link. Couldn't remember where it comes from. It must be quite old. We should delete this routing & controller.
Comment #17
adriancidThanks @eme I'' remove it in a few hours, and what about the redirects to drupal.org pages?
Comment #18
finne@eme: And what about the external links to drupal.org?
- ha oops double posts :-)
Comment #19
eme commentedOh, yes of course. That's way better.
Comment #20
adriancidSolved the problem with the route admin_development in #2916040: Remove unused route admin_development
Comment #21
finneHere is a patch that makes all pages cacheable again. The solution is to use a lazy builder for the menu items that have tokens in them.
Unfortunately core toolbar uses a complicated mechanism to determine cacheability of the toolbar menu, so you cannot just add/remove menu items, because the cachability is already saved at an earlier stage with the use of internal toolbar module functions :-( I worked around this by building a menu render array for the required menu items and merging them into the menu tree after it's build() function has run.
Please test & review.
Comment #23
adriancid@finne I will check later your patch.
the drupal.org links issue is #2916064: Use in drupal.org links url parameter and not route_name
Comment #24
finneNew patch that fixes the failing test (by checking an html string that is present even without the lazybuilder additions).
Comment #25
finneComment #27
adriancid@finne thanks for the patch, the only problem that I see is that the menu items don't have the same weight.
Comment #28
adriancid@finne and @eme I need that you test the patch to see if we can commit this soon.
Comment #29
finneChanges are OK. I checked the code and tested the patch on a clean 8.5.x install.
For reference I added the interdiff between 24 and 28.
I think this can be committed.
Comment #31
adriancid@finne thanks for the work.
And thanks to @all for made this possible ;-)
Comment #33
adriancidHi @finne, can you take a look at #2923466: Inconsistent dropdown behaviour with admin menu please?
Comment #34
eme commentedPatch has been reverted as it causes many errors. I'll re-organize this issue and list the problems raised by it. For now, it is unfortunately very erratic except the fact that in vertical mode the dropdown is broken.
Comment #35
fagoI ran into the same problem. While I wanted to fix it, I figured the problem is due to CSRF tokens in the links. But they were already correctly placeholdered. What was wrong was toolbar module, see #2949457: Enhance Toolbar's subtree caching so that menu links with CSRF token do not need one subtree cache item per session. -> The patch over there fixes the problem.
Comment #36
eme commentedSo what you say is that the patch here + #2949457: Enhance Toolbar's subtree caching so that menu links with CSRF token do not need one subtree cache item per session works well ?
Issue is that when we applied the patch in this post, the result was very erratic...
Comment #37
idebr commentedIf the Toolbar is fixed in Drupal core at #2949457: Enhance Toolbar's subtree caching so that menu links with CSRF token do not need one subtree cache item per session, this issue is solved without needing a patch.
Comment #38
adriancidComment #39
chris matthews commentedComment #40
chris matthews commentedComment #41
romainj commentedComment #42
romainj commentedIssue #2949457: Enhance Toolbar's subtree caching so that menu links with CSRF token do not need one subtree cache item per session is fixed!