Dynamic page cache seems to be incompatible with messages for anonymous users

Created on 17 February 2021, over 3 years ago
Updated 10 September 2023, 9 months ago

Problem/Motivation

We have a webform which set a confirmation message for anonymous users and also redirects. This does not work. This is just a PoC, we actually are using custom code which stores JS in a <code>FlashBag similarly to how @messenger does and we read the messages out in hook_page_attachments which do not fire for anon.

Steps to reproduce

I do not know how to reproduce this with core modules only.

But code reading / debugging shows the following:

  1. The NoSessionOpen returns NULL when a session is open (and allow when there isn't).
  2. The PageCache middleware strict compares to allow before serving the cache. Since NULL is not allow it does not.
  3. The DynamicPageCacheSubscriber class however strict compares to deny before not serving the cache. And since NULL is not deny either, it simply serves the cache and hook_page_attachments does not fire.

This seems to be the exact opposite of what's described at https://www.drupal.org/docs/administering-a-drupal-site/internal-page-cache โ†’

Websites that serve personalized content to anonymous users (dynamic, per-session, e.g. a shopping cart) will want to disable the Internal Page Cache module. This module assumes pages are identical for all anonymous users. Those websites can still take advantage of the Dynamic Page Cache module though,

Proposed resolution

It's possible there's just a documentation issue here? I am wondering whether this is as simple as adding session.exists to required_cache_contexts. If so then this could be moved to documentation -- but it would still need clarification regarding the internal page cache module.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ› Bug report
Status

Postponed: needs info

Version

11.0 ๐Ÿ”ฅ

Component
Dynamic page cacheย  โ†’

Last updated 2 days ago

Created by

๐Ÿ‡จ๐Ÿ‡ฆCanada Charlie ChX Negyesi ๐ŸCanada

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Woah! ๐Ÿ˜ณ

    Could you provide a sample module to reproduce this? ๐Ÿ™ Ideally a sibling test module of core/modules/dynamic_page_cache/tests/dynamic_page_cache_test โ€” that'd make it easy to write a test for this!

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sorabh.v6 Indore

    Hi Wim Leers,

    We are experiencing the same problem on a Drupal 10 site. This site is using the commerce module.

    Visit this demo site.
    https://commerce.demo.centarro.io/products

    Check your developer console, no session is created yet. Then you add a product to the cart and a session is created. Then you go to the catalog page or any other page then check the response in network tab then you will see that there is no X-Drupal-Cache and X-Platform-Cache is a miss too.

    Then if you delete the session cookie and reload the page then you will see that the X-Drupal-Cache and X-Platform-Cache is HIT.

    This is a major performance issue, because of this if an anonymous user is casually browsing through the site after adding product to cart then every request will reach the drupal server and won't be served from adding overhead to server.

    I was initially thinking it to be a commerce issue but then I saw this ticket and thought maybe its a Core issue.

    I hope my steps instruction willl make it easy to reprocude the issue.

    Thanks

  • Status changed to Postponed: needs info 10 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Check your developer console, no session is created yet.

    First: there's no way to verify this purely on the client side. It's possible that the server side did create/start a session and infrastructure between client and origin prevented that session cookie from reaching the client.

    Then you add a product to the cart and a session is created.

    Okay.

    Then you go to the catalog page or any other page then check the response in network tab then you will see that there is no X-Drupal-Cache and X-Platform-Cache is a miss too.

    X-Drupal-Cache is for the Internal Page Cache (page_cache.module), not the Dynamic Page Cache (dynamic_page_cache.module). X-Platform-Cache is non-Drupal.

    Dynamic Page Cache's header is X-Drupal-Dynamic-Cache: \Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber::HEADER.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sorabh.v6 Indore

    @Wim Leers I am not sure now how to properly provide the steps that would help to reproduce the issue. Can you tell me what more details is needed and how I can provide those details. I mean, how do I check this -

    It's possible that the server side did create/start a session and infrastructure between client and origin prevented that session cookie from reaching the client.

    Or is it drupal commerce related issue?

Production build 0.69.0 2024