Problem/Motivation

Core marked any entity form as uncacheable (max-age = 0) in #2578855: Form tokens are now rendered lazily, allow forms to opt in to be cacheable and this will be fixed in #3395524: Make entity forms cacheable.
However, after upgrading to Drupal 11 and seeing the flow on effects on our projects, I think we should manually remove this max-age in WebformSubmissionForm and opt back in to caching.

If you are using Webform on Drupal 11 with https://www.drupal.org/project/cache_control_override you will get pages without a max-age set in the Cache-Control header resulting in pages being uncacheable by the CDN (bad).

WebformSubmissionForms are cached in D10.4 and I don't think any of the issues that #3395524: Make entity forms cacheable will tackle will really apply to Webforms.

Steps to reproduce

  1. Install Standard profile
  2. Install webform 6.3.x
  3. Install webform_node
  4. Add a Webform node and reference the Contact form
  5. Visit the node and check headers, see that X-Drupal-Cache-Max-Age: 0 (Uncacheable). Note this header is only available when http.response.debug_cacheability_headers is enabled

Proposed resolution

Prevent max-age=0 from bubbling for anonymous users to restore caching on CDN

Issue fork webform-3505669

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

acbramley created an issue. See original summary.

acbramley’s picture

Issue summary: View changes
acbramley’s picture

Title: Make webforms cacheable again » Make webforms cacheable in Drupal 11
Issue summary: View changes
acbramley’s picture

Status: Active » Needs work

Gonna be a bit trickier than I first expected by the looks of the test failures. It seems like some things perhaps aren't setting the cacheable metadata that they should be on Webform's end and were just coincidentally passing before.

pminf’s picture

@acbramley Is this a general issue with Webform in Drupal 11 or just in combination with cache_control_override?

acbramley’s picture

@pminf unrelated to cache_control_override, it's just webform + D11

liam morland made their first commit to this issue’s fork.

j-lee’s picture

Is #3538483: Form build caching is broken in Drupal 11 a duplicated or a related issue?

bkosborne’s picture

Category: Bug report » Feature request

This seems like it's a feature request, not a bug?

In any case, I'm confused. Webforms ARE currently being cached in D11 (which has led to the bug reported in #3538483: Form build caching is broken in Drupal 11).

Core is only marking the form as uncacheable (max-age = 0) if the form doesn't already have a max-age set.

But webform submissions forms DO have a max-age set as I described in this comment.

bkosborne’s picture

acbramley’s picture

Category: Feature request » Bug report

It's definitely a bug, they were cacheable pre D11. And the line of code you linked to is not the bit that sets them as uncacheable, that's here

At least, this was the state of webform caching when I opened this issue.

acbramley’s picture

Issue summary: View changes

Confirmed with a fresh install. Updated steps to reproduce.

bkosborne’s picture

Title: Make webforms cacheable in Drupal 11 » Webforms no longer cacheable (max-age is set to 0) in Drupal 11 due to core change
Issue summary: View changes

Okay, I was conflating this a bit with #3538483: Form build caching is broken in Drupal 11 which has other circumstances that are leading to cache issues.

First I think we need to define what "cacheable" means here. I think for the purpose of this issue it means that the form doesn't bubble up a max-age of 0. That would make it uncacheble by Dynamic Page Cache, and it would also make it uncacheable by your CDN if you were using the Cache Control Override module which exposes that max-age to the cache header response (Drupal doesn't do this normally).

I agree that prior to core issue #2578855: Form tokens are now rendered lazily, allow forms to opt in to be cacheable, anonymous visits to a webform were cacheable and didn't have max-age=0. Authenticated visits wouldn't have been cacheable (by dynamic page cache) because the CSRF form token got added and had a hardcoded max-age=0 which bubbled up. After that core issue, the webform submission form has a forced max-age=0 regardless of there being a CSRF for token added or not.

bkosborne’s picture

Title: Webforms no longer cacheable (max-age is set to 0) in Drupal 11 due to core change » Webforms no longer cacheable for anonymous users (max-age is set to 0) in Drupal 11 due to core change
liam morland’s picture

bkosborne’s picture

I took a brief look at the failing test and it's related to the added cache context for the user authenticated role. It wasn't a simple/obvious fix. I may get to it this coming week.

idebr made their first commit to this issue’s fork.

liam morland’s picture

This issue and #3561066: Set max-age:0 for authenticated users to exclude Webforms from Dynamic page cache are classed as release-blockers for 6.3.0. Are the caching issues big enough that they ought to be release-blockers? Is there anyone able to look at this?

bkosborne’s picture

Yes IMO this should 100% be a release blocker

liam morland’s picture

thiagomoraesp’s picture

Confirmed here for logged in users, the entire page got
x-drupal-cache-max-age: 0 (Uncacheable)

The form is being showed on a paragraph using entity reference.

Have discovered a workaround on my specific scenario, use the "Use a lazy builder to render the form after the page is built/loaded." option on the entity reference content display and it should display the form and cache the page :D

liam morland’s picture

Tests are not passing. This likely needs to be solved in tandem with #3561066: Set max-age:0 for authenticated users to exclude Webforms from Dynamic page cache.

jwineichen’s picture

Issue tags: +Drupalcon Chicago 2026

Testing at DrupalCon Chicago 2026, running through the steps:

  1. When visiting webform node page as Anonymous or Authenticated shows X-Drupal-Cache-Max-Age: 0 (Uncacheable)
  2. After MR 597 with 2026-03-19 commits:
    • As Authenticated user: X-Drupal-Cache-Max-Age: 0 (Uncacheable)
    • As Anonymous user: X-Drupal-Cache-Max-Age: -1 (Permanent)
rachel_norfolk’s picture

Issue tags: -Drupalcon Chicago 2026 +Chicago2026

Correcting the issue tag for DrupalCon

idebr’s picture

Title: Webforms no longer cacheable for anonymous users (max-age is set to 0) in Drupal 11 due to core change » Prevent max-age=0 from bubbling for anonymous users to restore caching on CDN
Issue summary: View changes

The issue summary made the scope of this issue seem a bit bigger that it actually is:

  1. The page_cache module caches pages with a Webform regardless of max-age, at least until #2352009: Bubbling of elements' max-age to the page's headers and the page cache is fixed in Core
  2. This only affects Drupal sites running on a CDN

I have updated the issue summary to limit the scope to anonymous users to fix only the bubbling of max-age=0.

idebr’s picture

Status: Needs work » Needs review

The code changes are now limited in scope to anonymous users.

j-lee’s picture

Code looks fine to me. But I can not test it on a CDN.

luke.leber’s picture

Status: Needs review » Needs work

Setting back to NW based on review over in Gitlab.