Problem/Motivation

The node_read_time.reading_time service stores calculated reading time in an object property. After rendering one node with text, the module clears only the "words" property by calling setWords(0). It does not clear the "readingTime" property.

If the same shared service instance later calculates reading time for a node with no readable words, calculateReadingTime() returns early without resetting the previous reading time. This can make an empty node display the previous node's reading time in the same request, for example on a listing page that renders multiple nodes.

Node Read Issue

Steps to reproduce

1. Install Drupal 11.4.
2. Install and enable Node Read Time 8.x-1.15.
3. Configure reading time for the Article content type.
4. Enable the reading time extra field/display on a teaser or full display.
5. Create Article A with a body long enough to show a reading time.
6. Create Article B with no body/readable text.
7. Create a View or listing that renders Article A followed by Article B in the same request.
8. View the listing.

Proposed resolution

Reset readingTime before every calculation or when words are cleared.

Possible fixes:
1. Set $this->readingTime = NULL at the start of calculateReadingTime().
2. Update setWords(0) to also reset readingTime.
3. Avoid mutable shared state in the service and return a calculated value
directly.

CommentFileSizeAuthor
Article-A-and-B-Content.png123.15 KBdkmishra

Comments

dkmishra created an issue.