Problem/Motivation

QuickTabsController::ajaxContent() uses AjaxResponse, which does not implement CacheableResponseInterface. Cache metadata (tags, contexts) from the
rendered tab content is not bubbled onto the response. Dynamic Page Cache cannot cache the response. Core's ViewAjaxController uses CacheableAjaxResponse and bubbles
cache metadata for the same pattern (see core/modules/views/src/Controller/ViewAjaxController.php lines 148, 222–227).

Proposed resolution

Replace AjaxResponse with CacheableAjaxResponse and bubble cache metadata from the rendered content onto the response, matching what core's Views AJAX controller
does:

$response = new CacheableAjaxResponse();                                                                                                                                                
  $response->addCommand(new HtmlCommand($element_id, $render));                                                                                                                                      
  $response->addCacheableDependency(CacheableMetadata::createFromRenderArray($render));                                                                                                              
  $response->addCacheableDependency($qt);

Issue fork quicktabs-3606675

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

loze created an issue. See original summary.

loze’s picture

Issue summary: View changes

loze’s picture

Status: Active » Needs review
joelpittet’s picture

Oh I didn’t expect it wouldn’t bubble it! Thanks loze!

loze’s picture

Added missing $response->addCacheableDependency(CacheableMetadata::createFromRenderArray($render)) to bubble rendered content cache metadata to the response.

  • joelpittet committed a4ef11d6 on 4.0.x authored by loze
    #3606675 Use CacheableAjaxResponse for AJAX tab content
    
joelpittet’s picture

Added a quick test to make sure we’re making a diff (red/green) for caching, chose a functional so we don’t test interfaces exist.

All working great, thanks again @loze!

joelpittet’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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