Preview responses shouldn't be cached by default.

Created on 16 November 2020, about 4 years ago
Updated 14 August 2024, 4 months ago

First, many thanks to anyone who has contributed to this module!

Problem/Motivation

Embed preview controller forces a response cache of 5 minutes. This can lead to editorial confusion when editing embeds from a separate page, and then coming back to a content form, as it still shows the old, cached contents. The code doing this:

    // Note that we intentionally do not use:
    // - \Drupal\Core\Cache\CacheableResponse because caching it on the server
    //   side is wasteful, hence there is no need for cacheability metadata.
    // - \Drupal\Core\Rendr\HtmlResponse because there is no need for
    //   attachments nor cacheability metadata.
    return (new Response($html))
      // Do not allow any intermediary to cache the response, only the end user.
      ->setPrivate()
      // Allow the end user to cache it for up to 5 minutes.
      ->setMaxAge(300);

I'm filing this under bug category and not task even if the existing caching is done on purpose. My understanding is that the context where these previews are used, is exclusively wysiwyg embedded, which is most of the time, a behind-auth, editorial feature. As such, if there's a place where an editor would expect contents to be the current ones, is precisely the wysiwyg editor.

Steps to reproduce

1. configure a node form to use entity embed in the wysiwyg.
2. Embed some other node and save.
3. Edit (e.g change the title) the embedded node on its own page, and save.
4. Load again in a new tab the first node's form. (Make sure you don't have browser console tools or anything opened that could cause the browser to ignore cache).
5. The embedded view still shows the cached content.
6. Open browser console, ignore caches, and load again the page. Now the contents are updated.

Proposed resolution

- Make this a global setting in entity_embed, and surface it in "/admin/config/content/embed/settings". Potentially default it to no caching at all, as that's the default expectation in any wysiwyg editor anyway.

Hopefully this sounds a reasonable thing to add!

Remaining tasks

- Add setting to schema and make controller use it.
- Tests.

User interface changes

- Textfield / numeric field in "/admin/config/content/embed/settings".

API changes

- None.

Data model changes

- Only config schema.

πŸ› Bug report
Status

Active

Version

1.0

Component

CKEditor integration

Created by

πŸ‡ͺπŸ‡ΈSpain slv_

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