Views RSS Feed Fields adds <time> tag.

Created on 24 August 2023, over 1 year ago
Updated 13 January 2024, 12 months ago

Problem/Motivation

When creating a view with the page-type of Feeds, RSS Feed, and fields (vs content), the date field adds a <time> tag:
<pubDate><time datetime="2023-08-10T13:43:13-07:00" class="datetime">Thu, 10 Aug 2023 13:43:13 -0700</time></pubDate>

I've chosen "major" as this broke a bunch of our feeds, and I'd imagine it does the same for many other folks.

This also causes Planet Drupal to sometimes be flooded with a lot of old items from a feed, after the site got updated to Drupal 10, see 🐛 Prevent flooding of feeds such as Drupal Planet with old blog posts Closed: duplicate . From release Drupal 10.2.1 this should be fixed.

Steps to reproduce

  • Create a view
  • Create a Feed
  • Add the appropriate fields (I chose Title, Body, Authored By, Authored On, Link to Content, and UUID)
  • Set the format to RSS Feed
  • Set Show to Fields
  • Map the Field Settings to point to the appropriate fields
  • The feed will have an added <time> as illustrated above.

Thanks!

🐛 Bug report
Status

Fixed

Version

10.2

Component
Views 

Last updated about 8 hours ago

Created by

🇺🇸United States greatmatter

Live updates comments and jobs are added and updated live.

Missing content requested by

🇦🇺Australia dpi
about 1 year ago
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.

  • Issue created by @greatmatter
  • 🇺🇸United States greatmatter

    In case anyone lands on this, our workaround is to enable "rewrite results" for the field, and use twig:
    {{ created__value|date('D, d M Y H:i:s O') }}
    This "fixes" it.

  • Status changed to Postponed: needs info over 1 year ago
  • 🇳🇱Netherlands Lendude Amsterdam

    Thanks for posting your issue and workaround, I have some questions that might help get

    this broke a bunch of our feeds

    When did this break a bunch of feeds, was this after an update? If so, which one? It might help track down what changed this. Or is this just an issue when creating any new Feed that doesn't align with how the feed should be formatted?

    Also, I'm wondering, is this just using core/modules/system/templates/time.html.twig for rendering? And if so, is this a problem in Views or somewhere else?

  • 🇺🇸United States greatmatter

    @lendude - It's hard to say, because I was notified by a volunteer. If I had to guess, it was around the time we updated the site to Drupal 10, but I can't be sure.

  • 🇬🇧United Kingdom powysm

    I am seeing this on my REST Export feeds after updating Drupal from 9.5.11 to 10.1.4.
    I am surprised this is not better documented somewhere, if it is I haven't found it.

    I worked around this by checking "Strip HTML tags" and "Remove whitespace" under "rewrite results".

  • 🇩🇪Germany pminf Nuremburg (Germany), formerly Dresden

    We updated Drupal from 9.5.10 to 10.1.4.

    @lendude The template doesn't seem to matter. The markup of all our field based feeds changed from

    <pubDate>
    
    <!-- THEME DEBUG -->
    <!-- THEME HOOK: 'views_view_field' -->
    <!-- BEGIN OUTPUT from 'core/themes/stable/templates/views/views-view-field.html.twig' -->
    Tue, 26 Sep 2023 12:55:17 +0200
    <!-- END OUTPUT from 'core/themes/stable/templates/views/views-view-field.html.twig' -->
    
    </pubDate>
    

    to

      <pubDate>
    
    <!-- THEME DEBUG -->
    <!-- THEME HOOK: 'views_view_field' -->
    <!-- BEGIN OUTPUT from 'themes/contrib/stable/templates/views/views-view-field.html.twig' -->
    
    
    <!-- THEME DEBUG -->
    <!-- THEME HOOK: 'time' -->
    <!-- BEGIN OUTPUT from 'themes/contrib/stable/templates/field/time.html.twig' -->
    <time datetime="2023-09-26T12:55:17+02:00">Tue, 26 Sep 2023 12:55:17 +0200</time>
    
    <!-- END OUTPUT from 'themes/contrib/stable/templates/field/time.html.twig' -->
    
    
    <!-- END OUTPUT from 'themes/contrib/stable/templates/views/views-view-field.html.twig' -->
    
    </pubDate>
    

    As you can see we are using a theme based on contrib stable. But the issue is also present when using the current stark theme with core/modules/system/templates/time.html.twig:

      <pubDate>
    
    <!-- THEME DEBUG -->
    <!-- THEME HOOK: 'views_view_field' -->
    <!-- BEGIN OUTPUT from 'core/modules/views/templates/views-view-field.html.twig' -->
    
    
    <!-- THEME DEBUG -->
    <!-- THEME HOOK: 'time' -->
    <!-- BEGIN OUTPUT from 'core/modules/system/templates/time.html.twig' -->
    <time datetime="2023-09-26T12:55:17+02:00">Tue, 26 Sep 2023 12:55:17 +0200</time>
    
    <!-- END OUTPUT from 'core/modules/system/templates/time.html.twig' -->
    
    
    <!-- END OUTPUT from 'core/modules/views/templates/views-view-field.html.twig' -->
    
    </pubDate>
    

    I can confirm the workaround from #5:

      <pubDate>
    
    <!-- THEME DEBUG -->
    <!-- THEME HOOK: 'views_view_field' -->
    <!-- BEGIN OUTPUT from 'themes/contrib/stable/templates/views/views-view-field.html.twig' -->
    
    
    
    Tue, 26 Sep 2023 12:55:17 +0200
    
    
    <!-- END OUTPUT from 'themes/contrib/stable/templates/views/views-view-field.html.twig' -->
    
    </pubDate>
    

    (Ignore the whitespaces. They are not present if theme debug is disabled.)

  • We are currently experiencing this in all of our Views Rest Exports (the ones with time fields, anyway) after upgrading from Drupal 9.5.11 to Drupal 10.1.5 and running `drush updb`. Looks like there is an update in the list that is likely the cause (highlighted text in attached screenshot).

    #5 solves the issue, but since we are running headless, this affects a lot of our endpoints and is unfortunately causing a heck of a lift between identifying and manually editing all of the affected views

  • Status changed to Active about 1 year ago
  • 🇺🇸United States papagrande US West Coast

    Same problem for me--updated to D10 and RSS feeds break. And the workaround in #5 fixes it.

    Based on git blame it looks like the change was introduced in https://www.drupal.org/project/drupal/issues/2921810 🐛 Allow TimestampFormatter to show as a fully cacheable time difference with JS Fixed . Perhaps the Views RSS row formatter needs tweaking to exclude the <time> element.

  • 🇳🇱Netherlands Lendude Amsterdam

    #8 seems to point to the right issue, looking at the MR, this change was needed there:

        $this->assertEquals($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'custom', 'Y'), $executable->getStyle()->getField(0, 'created'));
    

    to

        $this->assertEquals($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'custom', 'Y'), trim(strip_tags($executable->getStyle()->getField(0, 'created'))));
    

    Which would indicate that new things got added to the output there.

  • 🇫🇮Finland heikkiy Oulu

    We encountered the same issue in two projects that updated from core 9.5.11 to 10.x. We were able to hotfix this by enabling the Strip HTML tags (strip_tags) and Trim whitespace (trim_whitespace) options in the view.

  • 🇩🇰Denmark ressa Copenhagen

    @Dave Reid pointed me to this issue, which explains the occasional flooding of old blog posts on Drupal Planet.

  • 🇩🇰Denmark ressa Copenhagen

    Marking up <time> as code, since it is invisible otherwise :)

  • 🇳🇴Norway hansfn

    I guess we could apply the "fix" in comment #5 in RssFields::render. The date field doesn't have a formatter without the time element so we need to strip to get pubDate as plain text.

  • Merge request !5763RSS pubDate contains HTML → (Open) created by Lendude
  • Status changed to Needs review about 1 year ago
  • 🇳🇱Netherlands Lendude Amsterdam

    Stripping tags on the pubDate sounds logical, that shouldn't contain HTML

    Added that as a fix and added test coverage

  • 🇫🇮Finland heikkiy Oulu

    I tested the fix from #16. It seems to fix the problem and I didn't see any extra empty space either in my testing.

    Probably makes sense to have a second review also and check the tests attached.

  • 🇳🇱Netherlands Lendude Amsterdam

    The test was showing the reported whitespace, so lets trim that too

  • 🇳🇱Netherlands Lendude Amsterdam

    Added a comment explaining why we are doing this

  • 🇫🇮Finland heikkiy Oulu

    Great! I tested it myself the following way:

    1. Removed the Strip tags and trim settings mentioned #10.
    2. Verified that the time tag was in back in the feed.
    3. Applied the patch.
    4. Verified that time tag was removed.

    I didn't encounter the whitespace issue when checking the actual feed so great that it was catched by the tests. Might have been a browser feature when checking the feed.

    I vote this could be marked as RTBC.

  • Status changed to RTBC about 1 year ago
  • 🇺🇸United States papagrande US West Coast

    Looks great! Thanks @Lendude and @HeikkiY.

    • catch committed 2e94575d on 11.x
      Issue #3383219 by Lendude, greatmatter, HeikkiY, PapaGrande, hansfn:...
  • Status changed to Fixed about 1 year ago
  • 🇬🇧United Kingdom catch

    Committed/pushed to 11.x and cherry-picked to 10.2.x, thanks!

    • catch committed f7e93f2a on 10.2.x
      Issue #3383219 by Lendude, greatmatter, HeikkiY, PapaGrande, hansfn:...
  • 🇩🇰Denmark ressa Copenhagen

    Thanks everyone! There was another surge of old posts on Drupal Planet today, but from Drupal 10.2.1 it looks like this should be fixed.

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

Production build 0.71.5 2024