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?

Comments

rgpublic created an issue. See original summary.

eme’s picture

Priority: Normal » Major

Hum, strange indeed. Seems major to me.

eme’s picture

Just 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 ?

rgpublic’s picture

Ah 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

eme’s picture

Status: Active » Closed (works as designed)

Indeed ! I close this issue then.

finne’s picture

NB: 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 :-(

eme’s picture

Priority: Major » Normal
Status: Closed (works as designed) » Active

Well, then it is certainly the CSRF token for the cache flush. Hard to see how to solve the issue.

finne’s picture

CSRF 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?

rgpublic’s picture

"... 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".

finne’s picture

StatusFileSize
new1.17 KB

Here 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.

adriancid’s picture

Version: 8.x-1.19 » 8.x-1.x-dev

@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.

finne’s picture

Assigned: Unassigned » finne

@adriancid thanks. I'm working on a lazybuilder for the cache and cron items, so the whole toolbar tools is cacheable again :-)

adriancid’s picture

@finne thanks, reviewing your patch I see the route:

admin_development:
  path: '/admin/development'
  defaults:
    _controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::development'
    _title: 'Development'
  requirements:
    _permission: 'administer site configuration'

That is only a redirect to:

  /**
   * Displays the administration link Development.
   */
  public function development() {
    return new RedirectResponse('/admin/structure/menu/');
  }

Do you have idea why we need this? Maybe @eme can help us?

finne’s picture

Re: #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.

adriancid’s picture

@finne let see if @eme can say something about this and I can change the behavior if needed.

eme’s picture

I 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.

adriancid’s picture

Thanks @eme I'' remove it in a few hours, and what about the redirects to drupal.org pages?

finne’s picture

@eme: And what about the external links to drupal.org?
- ha oops double posts :-)

eme’s picture

Oh, yes of course. That's way better.

adriancid’s picture

Solved the problem with the route admin_development in #2916040: Remove unused route admin_development

finne’s picture

Status: Active » Needs review
StatusFileSize
new7.01 KB

Here 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.

Status: Needs review » Needs work

The last submitted patch, 21: admin_toolbar_tools-2897309-21.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adriancid’s picture

@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

finne’s picture

New patch that fixes the failing test (by checking an html string that is present even without the lazybuilder additions).

finne’s picture

Status: Needs work » Needs review

The last submitted patch, 10: admin_toolbar_tools-2897309-10.patch, failed testing. View results

adriancid’s picture

Status: Needs review » Needs work

@finne thanks for the patch, the only problem that I see is that the menu items don't have the same weight.

adriancid’s picture

Status: Needs work » Needs review
StatusFileSize
new4.53 KB
new8.96 KB

@finne and @eme I need that you test the patch to see if we can commit this soon.

finne’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new4.53 KB

Changes 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.

  • adriancid committed 1dc1435 on 8.x-1.x authored by finne
    Issue #2897309 by finne, adriancid, eme, rgpublic: admin_toolbar_tools...
adriancid’s picture

Status: Reviewed & tested by the community » Fixed

@finne thanks for the work.

And thanks to @all for made this possible ;-)

Status: Fixed » Closed (fixed)

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

adriancid’s picture

Hi @finne, can you take a look at #2923466: Inconsistent dropdown behaviour with admin menu please?

eme’s picture

Status: Closed (fixed) » Active

Patch 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.

fago’s picture

I 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.

eme’s picture

So 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...

idebr’s picture

If 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.

chris matthews’s picture

Assigned: finne » Unassigned
chris matthews’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
romainj’s picture

Status: Active » Closed (won't fix)
romainj’s picture

Issue #2949457: Enhance Toolbar's subtree caching so that menu links with CSRF token do not need one subtree cache item per session is fixed!