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.