NodeController::revisionOverview is uncacheable

Created on 11 August 2021, over 3 years ago
Updated 18 December 2023, over 1 year ago

Problem/Motivation

NodeController calls $this->renderer->addCacheableDependency with an object that doesn't implement CacheableDependencyInterface, this results in an uncacheable page for DPC.

Steps to reproduce

Visit the node overview page
Notice that the page is uncacheable in dynamic page cache

Proposed resolution

username is a render array, use the correct API for merging cacheability metadata

Steps to test

1. On a fresh install of Drupal 9.3.x, apply the patch.
2. Create a node (can be published or unpublished).
3. Edit the node you created.
4. Open the web developer tools Inspect pane and select the Network tab.
4. View the node and click on its Revisions tab.
5. On the Network tab in your browser's Inspect tab, scroll up to the request for /revisions and select that row. In the adjacent tab, look under Respsonse Headers for the `x-drupal-dynamic-cache` row and note the value (should be MISS). Refresh the page and repeat, noting the new value (should be HIT).

Remaining tasks

1. Verify patch sets the x-drupal-dynamic-cache response header on node/%/revisions, i.e. node/1/revisions.
2. Add test coverage to verify that if the username is updated, the cache metadata that uses the username is also updated.

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Node system 

Last updated about 8 hours ago

No maintainer
Created by

🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

Live updates comments and jobs are added and updated live.
  • Needs manual testing

    The change/bugfix cannot be fully demonstrated by automated testing, and thus requires manual testing in a variety of environments.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇵🇭Philippines abhaypai

    Came here from Bug smash initiative. I am still able to replicate this issue on D11 and tried initial level of debugging.

    Wondering why CacheableMetadata::createFromRenderArray($username)->addCacheableDependency($node) or CacheableMetadata::createFromRenderArray($username) are not working as expected. Checked type of argument that i am passing and also looked into multiple other ways of defining it, still x-drupal-dynamic-cache is not coming on response headers.

    Might need some more insights here from the community.

  • Status changed to Needs review over 1 year ago
  • 🇵🇭Philippines abhaypai

    Might need some more insights here from the community, thats why moving it to Needs review status.

    Is it designed that way or needs fix ? note i am aware of related issue https://www.drupal.org/project/drupal/issues/3232018 and from my POV possibly we need to take some action on this issue, since it is affecting in many more pages with x-drupal-dynamic-cache: UNCACHEABLE in response headers.

  • Status changed to Postponed: needs info over 1 year ago
  • Status changed to Needs work over 1 year ago
  • 🇬🇧United Kingdom catch

    This doesn't need more info, the bug has been reproduced in #32 and also previously, it does need a conversion to an MR though at least.

  • 🇮🇳India Akhil Babu Chengannur

    By default, x-drupal-dynamic-cache header is present when revision oveview page is accessed and its value is 'UNCACHEABLE'.

    Now, If revision overview page is accessed after applying patch #17, x-drupal-dynamic-cache header wont be there. This is due tho the following condition in onResponse() method of DynamicPageCacheSubscriber.

        // Don't cache the response if the Dynamic Page Cache request & response
        // policies are not met.
        // @see onRequest()
        if ($this->requestPolicyResults[$request] === RequestPolicyInterface::DENY || $this->responsePolicy->check($response, $request) === ResponsePolicyInterface::DENY) {
          return;
        }
    
    

    $this->responsePolicy->check() calls several policy rules and Drupal\dynamic_page_cache\PageCache\ResponsePolicy\DenyAdminRoutes rule returns 'deny' for revison overview route as its an admin route. (_admin_route: true). So x-drupal-dynamic-cache header is omitted.

  • First commit to issue fork.
  • 🇦🇺Australia acbramley

    Rebased against 11.x, removed the ->addCacheableDependency($node) addition (out of scope), and moved testing to a dedicated test case since we need to disable the use_admin_theme setting.

  • Pipeline finished with Failed
    24 days ago
    Total: 636s
    #457552
  • Pipeline finished with Success
    24 days ago
    Total: 1541s
    #457557
  • Pipeline finished with Success
    22 days ago
    Total: 140912s
    #457570
  • 🇺🇸United States smustgrave
    1) Drupal\Tests\node\Functional\NodeRevisionsUiTest::testNodeRevisionsCacheability
    Behat\Mink\Exception\ExpectationException: Current response header "X-Drupal-Dynamic-Cache" is "UNCACHEABLE (poor cacheability)", but "MISS" expected.
    /builds/issue/drupal-3227637/vendor/behat/mink/src/WebAssert.php:888
    /builds/issue/drupal-3227637/vendor/behat/mink/src/WebAssert.php:180
    /builds/issue/drupal-3227637/core/tests/Drupal/Tests/WebAssert.php:969
    /builds/issue/drupal-3227637/core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php:229
    FAILURES!
    Tests: 5, Assertions: 52, Failures: 1.
    
    

    Shows test coverage

    Change seems straight forward and gone through a number of reviews. Believe feedback has been addressed.

  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    Committed and pushed 44f56c2c1b8 to 11.x and 371936c49aa to 11.1.x. Thanks!

    • alexpott committed 371936c4 on 11.1.x
      Issue #3227637 by larowlan, acbramley, daffie, amber himes matz,...
    • alexpott committed 44f56c2c on 11.x
      Issue #3227637 by larowlan, acbramley, daffie, amber himes matz,...
Production build 0.71.5 2024