dynamic page cache hit preventing confirmation to show

Created on 1 November 2024, about 2 months ago

Problem/Motivation

I have a situation where I'm on the product page, the dynamic page cache is hit. I add the product to cart and than the post request is done which redirects than to the same product page (regular behaviour for add to cart
Because the page gets a hit in dynamic page cache, the commerce_add_to_cart_confirmation_page_attachments does not get called, thus the confirmation is not added to the page.

Steps to reproduce

I do see in the simplytestme that the dynamic page cache gets a miss on same page after adding to cart, but don't know from where :(

Proposed resolution

I'm missing something? Quite strange for me to not see this issue in issue queue, affecting others, but seems kind of logical to happen :(

I'm thinking as an alternative, should this be a block with lazybuilder instead?

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇷🇴Romania dragos-dumi

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

Comments & Activities

  • Issue created by @dragos-dumi
  • 🇩🇪Germany Anybody Porta Westfalica

    Logically, it makes sense to me, what you're writing. On the other hand, I'm also wondering if nobody else ran into this yet.
    For the effect of this possible bug, I'm setting priority to major to gain attention. Best would be to create a test case first, which reproduces this issue?

    Sadly I'm not very experienced with caching-enabled tests, but perhaps someone can help here? Or with the general issue?

  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica

    Another thing just came to my mind: Does the regular "Added to cart" confirmation (Drupal message) appear?
    If not, this would mean that all commerce installations would be affected by this bug, which seems quite unrealistic?

    Can you reproduce this issue in a more or less vanilla environment or simplytest.me just using the essentially needed modules for reproduction?

  • 🇷🇴Romania dragos-dumi

    So I tracked down the initial issue to the fact that I had in the cart view, the remove button. This was, for some weird reason, messing up with the bubbling of cache metadata when having big pipe. This prevented the page to get cart context and commerce_order:ID tags which would have made the page dynamic cache invalid (assuming that the cart block is in all pages from where you can add a product)

    So the confirmation message works, as it seems, only if you have the cart block in the page, which would make the cache invalid when cart changes.

    Now there's a second issue as I see, which makes sense to be happening. The confirmation does show up now and gets cached in the page.
    This I replicated in having a clean commerce demo kickstart installed + this module.

    for this 2nd issue I attach a patch with max-age 0 when there's settings appended.

    for the 1st issue, I guess we should state in the modules page that it 'requires' cart block to be in the page? or somethign like that?
    An alternative would be to enforce the cache tags and context via this modules hook, but it would be bit weird as it would affect all pages, and one might not want that.
    An alternative would be to have been a block with lazy builder and the user 'can choose' which pages gets this feature.

Production build 0.71.5 2024