First entity view does not save recently read for anonymous users

Created on 6 September 2023, almost 2 years ago

Problem/Motivation

When trying to figure out why the tests are always failing I came across an interesting bug, that is not tested. When an anonymous user first visits a page and looks at some content that is supposed to be saved to recently read, it's not. Only when the user refreshes the page it occurs.

Steps to reproduce

  1. Install module.
  2. Add the block somewhere visible
  3. Create an article.
  4. Open private/incognito window
  5. Navigate to the website
  6. Navigate to the content
  7. At this point you can go back to the home page and you'll an empty block
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @admirlju
  • @admirlju opened merge request.
  • Status changed to Needs review almost 2 years ago
  • The problem happened because the first view did not correctly create a session. Tested locally with test from 📌 Drupal 10 Fix deprecations in tests Needs review .

  • 🇸🇮Slovenia deaom

    I can't reproduce the issue. Followed the steps described and the block is getting updated for anonymous user with the page visited. Not sure if this was fixed with any other issues merged. Leaving the status the same, so somebody else can also try and reproduce.

  • 🇸🇮Slovenia jernejmramor

    Hello, I've investigated this issue and was able to reproduce it, but only in some browsers. Firefox was working correctly, but for chrome I had to reload to get history. I've concluded that this is happening due to how Drupal is handling anonymous user sessions. Basically Drupal isn't creating sessions for anonymous users unless any module sets a session variable for the anonymous user. Because of this anonymous users gets their session_id logged as NULL the first time they see an entity. After that the session_id value gets set and all subsequent views are then logged correctly. A solution for this was added in 3413604 🐛 When set to "count based" old records never get expunged Active because with that we also ensure correct deletion of entries and preservation of entries for users that still have their sessions opened. I will close this issue after linked issue gets merged.

Production build 0.71.5 2024