Add hook/event to alter cache contexts that RefreshLess considers sensitive to changes

Created on 11 May 2022, over 3 years ago
Updated 30 August 2025, about 2 months ago

Problem/Motivation

Upon trying out the dev version on a site with custom cache contexts, I noticed that the module was not updating certain regions even though they do in fact vary by certain URLs, though indirectly. Specifically, on Omnipedia, we have a faux revision system that varies the site content based on an in-universe day. To make full use of Drupal's caching and minimize re-rendering, certain blocks (such as the date in the site header and the branding and sidebar links) don't have URL or route cache contexts, but do have a custom cache context for our in-universe dates (omnipedia_dates). While we could add URL or route cache contexts to these blocks, it would cause a lot more re-rendering that shouldn't be needed, as some of these blocks only ever have different contents based on this custom cache context.

Steps to reproduce

Create a custom cache context, apply it to a block in a region that has no other blocks with a URL or route cache context, browse site with RefreshLess active, notice the region with the custom cache context will not update. Edit Drupal\refreshless\RefreshlessPageState::isSensitiveContext() to include the custom cache context and RefreshLess now updates the region with the custom cache context.

Proposed resolution

Add a hook or event so that the default cache contexts in Drupal\refreshless\RefreshlessPageState::isSensitiveContext() can be altered by other extensions.

Remaining tasks

Do the code magic.

User interface changes

Probably none?

API changes

Add a hook, arrr.

Data model changes

TBD.

🐛 Bug report
Status

Closed: outdated

Version

1.0

Component

Code

Created by

🇨🇦Canada ambient.impact Toronto

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024