Problem/Motivation

When a Feed display is configured for a view the node RSS row plugin removes the #theme attribute from the built node data, causing the displayed nodes to render their fields individually instead of via the node template. However, the render element still contains the same caching information, causing it to be stored in the render cache as the output for that node & view mode (with a permanent max-age). Any other location where the node is displayed with that same view type will load the cached, incorrect, output.

Steps to Reproduce

1. Create a view with two displays; one Page display and one Feed display.
2. Configure both displays to show nodes using the same view mode
3. Ensure render caching is enabled
4. Rebuild site caches
5. Open incognito(private) browser window
6. Visit the Feed display
7. Visit the Page display

The page display outputs the nodes as concatenated field markup instead of using the node template.

7. Rebuild site caches
8. Load the Page display
9. Load the Feed display
The page display should now use the node template markup.

Proposed resolution

When Views renders an entity display for use in an RSS feed, it should set a cache key to differentiate the RSS-rendered version, so that the RSS-rendered version isn't incorrectly used in other contexts (such as when rendering the same entity display for an HTML page).

CommentFileSizeAuthor
#63 interdiff_61-63.txt639 bytesphilipnorton42
#63 2885098-63.patch9.02 KBphilipnorton42
#61 interdiff_57-61.txt5.4 KBphilipnorton42
#61 2885098-61.patch9.03 KBphilipnorton42
#57 interdiff_55-57.txt691 bytesphilipnorton42
#57 2885098-57.patch9.07 KBphilipnorton42
#55 2885098-55.patch9.09 KBphilipnorton42
#55 interdiff_54-55.txt2.02 KBphilipnorton42
#54 interdiff_42-54.txt916 bytesphilipnorton42
#54 2885098-54.patch8.93 KBphilipnorton42
#44 interdiff-40-42.txt2.14 KBphilipnorton42
#42 2885098-failing-test-42.patch8.34 KBphilipnorton42
#42 2885098-42.patch8.99 KBphilipnorton42
#40 2885098-40.patch9.59 KBphilipnorton42
#39 CleanShot 2020-10-21 at 15.19.08.gif10.32 MBamjad1233
#37 CleanShot 2020-10-21 at 09.16.55.gif1.61 MBamjad1233
#32 test1_rss_view.png285.98 KBbakulahluwalia
#32 test1_view_page.png115.72 KBbakulahluwalia
#30 2885098-30.patch1.34 KBSuresh Prabhu Parkala
#28 2885098_28.patch1.48 KBvsujeetkumar
#23 drupal-2885098-23-node-views-rss-no-cache.patch1.46 KBksbuble
#18 2885098-18.patch635 bytesMerryHamster
#11 drupal-2885098-11-node-views-rss-no-cache.patch635 bytesgapple
#8 interdiff.txt1.3 KBmohit1604
#7 drupal-2885098-7.patch1.4 KBgapple
#4 2885098-4.patch1.35 KBjoelpittet
#2 drupal-2885098-2-node-views-rss.patch579 bytesgapple

Issue fork drupal-2885098

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gapple created an issue. See original summary.

gapple’s picture

Status: Needs review » Needs work

The last submitted patch, 2: drupal-2885098-2-node-views-rss.patch, failed testing. View results

joelpittet’s picture

Status: Needs work » Needs review
FileSize
1.35 KB

Fix the cache context because now some of the theme will render out author user context.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

gapple’s picture

Issue tags: +Novice
FileSize
1.4 KB

Only difference from #4 is that the path to CommentRssTest.php has changed.

mohit1604’s picture

FileSize
1.3 KB
zymbian’s picture

Status: Needs review » Reviewed & tested by the community

Patch #7 looks good. Marking RTBC.

catch’s picture

Status: Reviewed & tested by the community » Needs work

If this is supposed to bypass the node template and now doesn't, won't that cause other problems?

gapple’s picture

I don't understand a reason for the node template to be bypassed in the first place, as it results in an unexpected override of the rendered node contents. If the intent is to output fields directly instead of a display mode, then the view should probably use the 'fields' row formatter instead.

An alternative, that would maintain the current behaviour, is to also remove the cache keys from the node to be rendered.

pifagor’s picture

Status: Needs review » Reviewed & tested by the community

looks good. Marking RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 11: drupal-2885098-11-node-views-rss-no-cache.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

Testbot had a hiccup re-rtbcing

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

This seems pretty important to have a test for.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

a.milkovsky’s picture

I am experiencing a similar problem. The patch #11 resolves the caching issue. Using Drupal 8.5.6.

MerryHamster’s picture

MerryHamster’s picture

Status: Needs work » Needs review
andypost’s picture

Status: Needs review » Needs work

NW for tests

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ksbuble’s picture

I am at Seattle Sprint and working on this issue.

ksbuble’s picture

Followed steps to reproduce with caching for Page and Feed set to Tag-based (for render caching). Not reproducible with Drupal core 8.7.0-dev environment from Community Tools Download (https://www.drupal.org/tools) using Devel 8.x-2.0 Generate to populate nodes.

Rerolled with code from patch 2885098-18.patch including test cases from drupal-2885098-11-node-views-rss-no-cache.patch.

yogeshmpawar’s picture

Status: Needs work » Needs review

Triggering bots.

Status: Needs review » Needs work

The last submitted patch, 23: drupal-2885098-23-node-views-rss-no-cache.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

vsujeetkumar’s picture

Status: Needs work » Needs review
FileSize
1.48 KB

Re-roll patch created for 9.1.x

Status: Needs review » Needs work

The last submitted patch, 28: 2885098_28.patch, failed testing. View results

Suresh Prabhu Parkala’s picture

Status: Needs work » Needs review
FileSize
1.34 KB

Please review.

mradcliffe’s picture

Status: Needs review » Needs work
Issue tags: +Global2020, +Bug Smash Initiative

Thanks for the patch. I moved this back to Needs work. I think at this point it makes sense to work on a test that will demonstrate the bug. I think this is still a Novice issue.

bakulahluwalia’s picture

Status: Needs work » Postponed (maintainer needs more info)
FileSize
115.72 KB
285.98 KB

Can't reproduce the bug. Tried the following:
Test Case1:
1) Created view as content with type: article [already have 1 node created as article]
2) the page view with Format:Unformatted list | Settings and Show:Content | Full content. Caching: tag based, Path:/global2020
3) Added new view as feed with Format:Unformatted list | Settings and Show:Content | Full content. Caching: tag based, Path:/feed/global2020
Views output
test1_page
test1_rss

Test Case2:
1) Created view as content with type: article [already have 1 node created as article]
2) the page view with Format:Unformatted list | Settings and Show:Content | RSS. Caching: tag based, Path:/global2020
3) Added new view as feed with Format:Unformatted list | Settings and Show:Content | RSS. Caching: tag based, Path:/feed/global2020
Output:
Both are showing expected results, page view showing title and RSS showing popup to download file.

Process:
1) Visited RSS page first then page
2) Visited page first then RSS page
3) Also tried with different formats still can't get the cached page.

mradcliffe’s picture

Thank you, @bakulahluwalia. Being able to triage issues is really important too.

I confirm that I tried to reproduce it following the steps and wasn't able to reproduce it.

I changed Caching to something other than None in Administration > Configuration > Development > Performance, and after creating the view, I cleared cache, visited the Feed, noted the fields, visited the page, and I saw the content rendered and the markup was based on the node template.

I think if this issue still exists, we would need to update the Steps to reproduce and write a failing test first.

Berdir’s picture

> I changed Caching to something other than None in Administration > Configuration > Development > Performance

The _only_ affect this setting has is the Cache-Control HTTP header.

Based on the code, this is about the render cache. I didn't try to reproduce yet, but the fix makes sense to me and I can see that this could happen.

Maybe try with a different view mode, there's special special handling around default, although full should work.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

gapple’s picture

Status: Postponed (maintainer needs more info) » Needs work
amjad1233’s picture

Hi,

I followed the steps as described in the issue but could not re-produce the results.

Is there anything we need this issue to get moving forward ?

gapple’s picture

@amjad1233 It is unclear from your screen capture if/when you cleared the cache, and what order afterwards you loaded the HTML and RSS displays of the view.

Does the markup of either display change depending on which display you load first after rebuilding the site cache?

amjad1233’s picture

Issue summary: View changes
FileSize
10.32 MB

Hi @gapple,

Sorry I think you're right. I was doing the wrong cache clearing sequence.

I am just uploading GIF here for anyone to see the issue visually.

@berdir the above screenshot is in Full display mode.

Regards,
Amjad

philipnorton42’s picture

Status: Needs work » Needs review
FileSize
9.59 KB

Thank you for finding the solution to this. It's been driving me mad on my blog for months. I spent hours and hours tracking down where the problem is from but only managed to figure it was something to do with RSS feeds.

Essentially, the problem is that when you render the node in a RSS feed as a teaser view mode the default node template is used and that template is added to the render cache. This means that when you come to render the node as a teaser using the default template the RSS teaser cache is returned, which gives you the wrong template in your theme. I'm sure this problem exists with other view modes and entities.

I had a go at creating a test for this situation and managed to figure it out. The original fix for the Rss.php class is good, but change to the CommentRssTest test didn't make sense to me.

The good news is that I managed to create a test situation that demonstrates the problem and the fact that the fix is correct. Hopefully everything is clear in the attached patch.

Berdir’s picture

  1. +++ b/core/modules/node/tests/src/Functional/NodeRSSCacheTest.php
    @@ -0,0 +1,97 @@
    +
    +  /**
    +   * Ensure that the RSS cache of the node contains is rendered using the current theme.
    +   */
    +  public function testNodeRSSCacheContent() {
    

    Descriptions must not be longer than 80 characters. I think the comment is a bit confusing anyway. the comment on the class seems much clearer.

  2. +++ b/core/modules/node/tests/src/Functional/NodeRSSCacheTest.php
    @@ -0,0 +1,97 @@
    +    $node = $this->drupalCreateNode([
    +      'type' => 'article',
    +      'promote' => 1,
    +      'title' => 'Article Test Title',      ¶
    +      'body' => [
    

    trailing spaces.

  3. +++ b/core/modules/node/tests/src/Functional/NodeRSSCacheTest.php
    @@ -0,0 +1,97 @@
    +
    +    // Check the render caches for the node tester.
    +    $cache = $this->container->get('cache.render');
    +    $cid = 'entity_view:node:' . $node->id() . ':teaser:' . implode(':', \Drupal::service('cache_contexts_manager')->convertTokensToKeys(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'user.permissions'])->getKeys());
    +    $nodeTeaserCache = $cache->get($cid);
    +
    

    not sure if we really need to check the cache directly as well, kind of seems like an implementation detail. Tests like this tend to break if things are refactored.

You should also upload a test-only patch separately and first, to prove that your test fails without the fix.

philipnorton42’s picture

Hi Berdir,

Thanks very much for taking the time to review. I agree with all of the points raised. I was wondering about the cache issue as I was writing it. I felt like I needed to check and demonstrate that the cache was correct, but I was also thinking "this _might_ need fixing in the future". I'll need to keep an eye out for that feeling in the future :). Apologies about the code formatting issues, I should have spotted those.

I have a new patch with the changes applied and another patch without the original fix in place to show that the problem exists. Good idea about the second patch without the fix, I hadn't thought of doing that.

Thanks,
Phil

Status: Needs review » Needs work

The last submitted patch, 42: 2885098-failing-test-42.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

philipnorton42’s picture

FileSize
2.14 KB

Adding interdiff between #40 and #42.

philipnorton42’s picture

Status: Needs work » Needs review
jplana’s picture

+RTBC

I can confirm patch #42 fixed our long-standing problem, similar to other people have reported here: #2915636: node.html.twig intermittently being ignored

The steps I followed to reproduce was:

1. Clear the cache.
2. Visit a taxonomy term feed, for example: /taxonomy/term/%/feed that will generate the cache for the RSS feed
3. Visit a page with a view that displays the same content as the taxonomy term feed. I was getting the 'broken' rows displaying at this point.

Thank you very much @philipnorton42! You're a legend :)

jplana’s picture

Status: Needs review » Reviewed & tested by the community
gapple’s picture

catch’s picture

Status: Reviewed & tested by the community » Needs review

It seems like this will just completely remove render caching from RSS pages. Could we change the cache key instead of unsetting it?

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

rachel_norfolk’s picture

Trying this out on https://rachelnorfolk.me to see if it resolves https://twitter.com/rachel_norfolk/status/1389905214359146500.

Of course, an intermittent issue needs a few days to see how it goes…

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

philipnorton42’s picture

Thanks for the feedback catch.

I've had another go at doing this and rather than remove the keys I have added an additional key that references the view rss feed. After some testing this approach appears to work fine and the unit tests created work well also.

This seems like a better approach than just removing the cache keys. Ready for a review I think!

philipnorton42’s picture

FileSize
2.02 KB
9.09 KB

Looks like the test got tripped up on a coding standards thing that was introduced since the last coding standards check.

Fixed the issues in that file and re-created the fix.

philipnorton42’s picture

philipnorton42’s picture

FileSize
9.07 KB
691 bytes

Noticed an issue in the views.view.test_node_article_feed.yml file were the previous and next characters were being corrupted.

Sorted that out to keep things neat.

philipnorton42’s picture

Issue tags: +Prague2022
nlisgo’s picture

+++ b/core/modules/node/src/Plugin/views/row/Rss.php
@@ -110,12 +110,14 @@ public function render($row) {
-

Is this change intentional? If doesn't add value we should remove to reduce the diff.

nlisgo’s picture

+++ b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_article_feed.yml
@@ -0,0 +1,208 @@
+uuid: 39713110-fd07-4d68-9814-f4b56948b659

We should remove the uuid.

philipnorton42’s picture

FileSize
9.03 KB
5.4 KB

Thanks for the feedback nlisgo, much apprecaited.

I think the removal of the line in the render() method is fine. It was flagged as a coding standards issue though phpcs running locally and although it is technically out of the scope of the changes I was making, I think having this change ok.

Good spot about the uuid in the config file, I have removed that.

I have also changed the name of the class NodeRSSCacheTest to NodeRssCacheTest, which is also a coding standards change. Since this is a new class for this change I think that's fine in this case. It does bloat the interdiff a little bit though.

nlisgo’s picture

+++ b/core/modules/node/tests/src/Functional/NodeRssCacheTest.php
@@ -0,0 +1,87 @@
+    ViewTestData::createTestViews(get_class($this), ['node_test_views']);

The standard now seems to be static::class or self::class.

Everything else looks good to me.

philipnorton42’s picture

Also a good suggestion, I've used static::class as that gets around any late static binding issues with self::class.

Thanks again! o/

gapple’s picture

I would like to re-up my enquiry #11, that never got an answer:

I don't understand a reason for the node template to be bypassed in the first place, as it results in an unexpected override of the rendered node contents. If the intent is to output fields directly instead of a display mode, then the view should probably use the 'fields' row formatter instead.

I still think that having unset($build['#theme']); so that nodes aren't rendered through the template system is an unexpected behaviour, and changing the cache keys resolves the cached conflict but patches over a root issue.

Berdir’s picture

Views supports both, and while the pseudo-rendered entity approach in my experience never really works out, just straight out removing a feature far more complex than just fixing this bug. we have to deprecate it, possibly convert existing config to a field based configuration instead, people might need to update their default configuration, ...

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Can the issue summary be updated as there 2 proposed solutions. Can we highlight which one was chosen. Will help with the review.

mradcliffe’s picture

Adds issue summary update tag

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smokris’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs issue summary update

If I understand correctly, the remaining concerns have all been addressed:

  • catch's question in #49, addressed by philipnorton42 in #54
  • nlisgo's question in #59, addressed by philipnorton42 in #61
  • nlisgo's question in #62, addressed by philipnorton42 in #63
  • gapple's question in #64, addressed by Berdir in #65
  • smustgrave's question in #67, which I addressed just now by updating the issue summary

…and the patch still applies, so I'll set this issue back to RTBC.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work

The Needs Review Queue Bot tested this issue.

While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

smokris’s picture

Status: Needs work » Reviewed & tested by the community

I converted the patch to a merge request, as instructed by the above needs-review-queue-bot comment.

larowlan made their first commit to this issue’s fork.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Left some minor comments. Fine to self RTBC after addressing.

larowlan’s picture

Status: Needs work » Reviewed & tested by the community

I just applied suggestions for those two comments as they were minor, restoring status

larowlan’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

Comment module has the same issue, opened a follow-up #3418181: Comment RSS Views plugin causes wrong entity_view output to be cached

Committed to 11.x

As this is a bug and there is no risk of disruption, backported to 10.2.x

  • larowlan committed 2ee934d4 on 10.2.x
    Issue #2885098 by philipnorton42, gapple, ksbuble, MerryHamster, Suresh...

  • larowlan committed 77685755 on 11.x
    Issue #2885098 by philipnorton42, gapple, ksbuble, MerryHamster, Suresh...

Status: Fixed » Closed (fixed)

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