Status field caching still broken (for authenticated users)

Created on 7 August 2024, 5 months ago
Updated 19 September 2024, 4 months ago

Problem/Motivation

The caching of the status (open/closed) data has been a problem for a long time and there have been multiple iterations to fix it. The base problem is that when an opening/closing time border is passed, there is no good way to invalidate the caches which continue serving the old data. Even the current, ambitious efforts for calculating max-age don't help, and disabling cache for pages having this feature is obviously a wrong solution.

The field just doesn't get rendered again but sticks in the cache.

This has been working for a while since a JS workaround to update the field ( Fix Field cache for anonymous users using JS callback in Status formatter Fixed ). But now a client reported that the functionality is broken again. When debugging, I discovered that page cache is not the one storing the stale data, but it's the dynamic page cache instead. Thus, solutions that target the workaround to anonymous page cache users only, leave the functionality broken for authenticated users, and disabling page_cache breaks this for everyone. At least in my setup.

(I noticed this because we have the office hours data rendered from a field template in a way that didn't work for the module's current markup structure requirements anymore. Fixed this by adding an extra div container with the attributes object to the template.)

This is related to 🐛 Views with Open/Closed status are not updated Needs review but out of scope of that one.

Steps to reproduce

Drupal 10.3.

* Have dynamic page cache enabled and page cache disabled (uninstalled).
* Do a drush cr.
* Have a node field that shows the office hours status flag.
* Have an opening/closing time a minute or so in a future.
* Open the page both authenticated and anonymous
* Let the time pass over the set time limit
* Reload the page and check that the flag is not refreshed in neither browser session.
* Have page_cache enabled and repeat previous steps: the flag should start updating for anonymous users (after a JS request), but not for authenticated ones.

Proposed resolution

I don't have a good solution to rewrite the whole caching but for now, applying the JS workaround for all users will fix this for us at least.

Still, this might leave it broken for 🐛 Layout Builder Display for anonymous users cannot use JS callback Fixed Layout Builder users, but I can't confirm that myself.

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code - formatter

Created by

🇫🇮Finland jhuhta

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

Comments & Activities

  • Issue created by @jhuhta
  • Issue was unassigned.
  • Status changed to Needs review 5 months ago
  • 🇫🇮Finland jhuhta

    This patch fixes the issue for us. I can make an MR out of it if the maintainer thinks this makes any sense.

  • 🇳🇱Netherlands johnv

    Indeed, in the efforts to fix the field cache problems, I only experienced (and only got reports from the audience) for anonymous users (with Internal Page Cache module enabled).
    Apparently, your client has a setup that also breaks cache for known users (with Internal Dynamic Page Cache module enabled).

    I cannot reproduce the error (neither when displaying a node,nor when displaying Views Fields)

    Let me check your fix, since it may harm performance on the majority of sites.

  • 🇳🇱Netherlands johnv

    I am not sure. Your test case is exactly the same as mine.

    I prefer leaving the code as-is, until i get some more reports with the same problem.
    In the past, many people attributed to the field caching,

Production build 0.71.5 2024